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 perform arithmetic operations between two operands.It includes +,-,*,/.
Program

a = int (input("Please enter a digit"))
b = int (input("Please enter a digit"))
c = int (input("Please enter a digit"))
d = a+b+c
print("Addition : ",d)
d = a-b-c
print("Subtraction : ",d)
d = a*b*c
print("Multipication : ",d)
d = a/b/c
print("Divion : ",d)
d = a%b%c
print("Modulus : ",d)

5. Describe about different Bitwise operator in Python with approproate examples.
Ans: The Bitwise operator perform a bit by bit operation on operrands

Program

a,b=5,1
c=a<<b
print(c)
c=a>>b
print(c)

Comments

Popular posts from this blog

State use of pep and pip