Posts

Showing posts from August, 2020

Practical No 5 : Write Python program to demonstrate use of looping statement : "while " loop ,"for loop" and Nested loop ((MSBTE Pratical Question))

1. What would be the output from the following Python code segment x = 10 while x<5:     print x,     x = 1 Ans : Raised an error parenthesis required 2. Change the Python code from using a while loop to for loop: x =1 while x<10:     print x     x+=1 Ans: for i in range 10:     print(x)

Practical No 4: Write simple Python program to demonstrate use of conditional statement :if statement ,"if else statement" , Nested if statement ((MSBTE Pratical Question))

1. List operations used in conditional statement  Comparision Operator Logical Operator Identity Operator Membership Operator 2. Differentitate between if-else and nested-if statement Ans: if-else : Here their only single pair of if - else statement nested if statement         Here the statement is nesteed means their is a group of if statment inside another if statement

Practical No. 3: Write a simple Python program using operators : Arithmetic ,Logical ,Bitwise Operators. ((MSBTE Pratical Question))

1. Mention the use of //.**,% operator in python Ans :  // this operator is used to do floor division ** this operator is used to do Exponet % this operator is used to do Modules 2. Describe the ternary operator in Python Ans Ternary operator is used to test a condition and then assign the corresponding value to a variable or execute a peice of code Syntax: [on true] if [expression] else [on false] 3. Describe about different Logical operators in Python with appropriate examples Ans Logical Operators are used in making Decession and : if both experssion are true it returns true else false or : if one expression is true it returns true else false not : it reverses the expression Program: a = int(input("Enter any Number")) if (a%4==0 and a%100!=0 or a%400==0):     print(a, " is a leap year") else:     print(a,"is not a leap year") 4. Describe about different Arithmetic operators in Python with appropriate examples. Ans: Arithmetic operators are used to perfo

Practical No. 2: Write simple Python program to display message on screen ((MSBTE Pratical Question))

1. List different modes of Programming in Python? Ans: Their are basically two types of mode Script Mode Interactive Mode 2. Describe procedure to execute program using Interactive Mode? Ans: To start interactive mode navigate to cmd and just type in python2 or python3 3. State the steps involved in executing the program using Script Mode? Ans: To execute the file ins cript mode type in python in start execute the python program then press ctrl+n -> write your python code save the code and then press F5. 4. State the procedure to make file executable? Step1: Add Python to windows Path Step2: Open CMD Step3: Install the Pyinstaller Package pip install pyinstaller Step4: Save Your script file Step5: To create Execute copy the file path without the filename  Step6: Run pyinstaller --exefile python simptome.py step7: Navigate to dist folder in which ther is .exe file

Program to check for ZeroDivisionError Exception. ((MSBTE Pratical Question))

Image
Code: try:     a = int(input("Enter a number: "))     b = int(input("Enter a number: "))     c = a / b     print("Division:",c) except ZeroDivisionError:     print("Can't divide by zero!")   Output:

Program to create user-defined exception that will check whether the password is correct or not? ((MSBTE Pratical Question))

Image
Code: class ValidatePassword(Exception):     username = "Mhssp"     password = "Mhssp123"     def __init__(self, user, pas):         if (self.password == pas) and (self.username == user):             print("Login Successful!")         else:             print("Incorrect Password!") try:     user = input("Enter username: ")     pas = input("Enter password: ")     raise(ValidatePassword(user,pas)) except ValidatePassword as error:     print("A new Exception occured!", error)   Output: