Python Lab Manual (22616)Answers
Practical 3: Write Simple Python Program Using Operators Arithmetic Operators ,Logical operators , Bitwise Operators
*Practical Related Questions.
1)Mention the use of //, **, % operator in Python.
Ans=> 1) // - This is Arithmetic Operator Use for Floor Division.
2)**- This is Arithmetic Operator Use for Calculate First Operand Power to Second Operand .
3) %- This is Arithmetic Operator it returns the reminder of division.
2)Describe ternary operator in Python
Ans=> 1) Ternary operators are also known as conditional expressions are operators that evaluate something based on a condition being true or false .
2) Syntax : [on_true] if [expression] else [on_false]
false
3) Describe about different Logical operators in Python with appropriate examples.
Ans => 1) Logical Operators: Logical operators perform Logical AND, Logical OR and Logical
NOT operations. For logical operators following condition are applied.
2)For AND operator – It returns TRUE if both the operands (right side and left side) are true
3) For OR operator- It returns TRUE if either of the operand (right side or left side) is true
4) For NOT operator- returns TRUE if operand is false
Output :
False
True
False
4) Describe about different Arithmetic operators in Python with appropriate
examples.
Ans=>
Operation | Operator | Example in Python Shell | |
---|---|---|---|
Addition: Sum of two operands | + |
| |
Subtraction: Left operand minus right operand | - |
| |
Multiplication | * |
| |
Exponentiation: Left operand raised to the power of right | ** |
| |
Division | / |
| |
Floor division: equivilant to math.floor(a/b) | // |
| |
Modulus: Reminder of a/b | % |
|
5) Describe about different Bitwise operators in Python with appropriate examples.
Ans=>
1) &(AND) : Set each bit to 1 if both bits are 1
2) | (OR) : Set each bit to 1 if one of the two bits are 1
3) ^ (XOR): Set each bit to 1 if one bit is 1
4) ~ (NOT) : Inverts all bit
5)<< (LEFT SHIFT) : The left operand's value is moved
6) >> (Right shift): The left operand's value is moved right by the number of bits specified by the right operand
*Exercise
1) Write a program to convert U.S. dollars to Indian rupees.
Ans=>
rs=us*75
print("indian Currency =",rs,"rupees")
2. Write a program to convert bits to Megabytes, Gigabytes and Terabytes
Ans=>
byte = bits/8
megabyte = byte/1000000
gigabyte = megabyte/1000
terabyte = gigabyte/1000
print("MB = ", megabyte)
print("GB = ", gigabyte)
print("TB = ", terabyte)
3. Write a program to find the square root of a number
Ans=>
4. Write a program to find the area of Rectangle
Ans=>
5. Write a program to calculate area and perimeter of the square
Ans=>
6. Write a program to calculate surface volume and area of a cylinder.
Ans=>
7. Write a program to swap the value of two variables
Ans=>
0 Comments