PWP PR 3
PWP PR 3
#Enroll: 2205690362
#Batch: 2
Code:
#Operators in python
#Arithmetic Operator
print('1 + 4 = ', 1 + 4)
print('10 - 5 = ', 10 - 5)
print('5 * 2 = ', 5 * 2)
print('10 / 2 = ', 10 / 2)
print('2 ** 3 = ', 2 ** 3)
print('15 % 4 = ', 15 % 4)
print('17 // 5 = ', 17 // 5)
#Logical Operator
print('(8>9) and (2<9) = ', (8>9) and (2<9))
print('(9>8)and(2<9) = ', (9>8)and(2<9))
#Bitwise Operator
a = 10
b=4
Output:
1+4= 5
10 - 5 = 5
5 * 2 = 10
10 / 2 = 5.0
2 ** 3 = 8
15 % 4 = 3
17 // 5 = 3
(8>9) and (2<9) = False
(9>8)and(2<9) = True
(2==2) or (9<20) = True
(3!=3) or (9>20) = False
not(8>2) = False
not(2>10) = True
a&b = 0
a|b = 14
~a = -11
a^b = 14
a<<2 = 40
a>>2 = 2
Code:
#Convert U.S dollars to Indian rupees
print("Convert U.s dollar to Indian rupees")
usd = int(input("Enter the amount: "))
print("Rupees: ", usd * 82.5)
Output:
Convert U.s dollar to Indian rupees
Enter the amount: 2
Rupees: 16
Code:
#Convert bits to Megabytes, Gigabytes and Terabytes
print("Convert bits to Megabytes, Gigabytes and Terabytes")
b = int(input("Enter the bits: "))
B=b/8
kb = B / 1024
mb = kb / 1024
gb = mb / 1024
tb = gb / 1024
print("Megabytes: ", mb)
print("Gigabytes: ", gb)
print("Terabytes: ", tb)
Output:
Convert bits to Megabytes, Gigabytes and Terabytes
Enter the bits: 8796093022208
Megabytes: 1048576.0
Gigabytes: 1024.0
Terabytes: 1.0
Code:
#Square root of a number
print("Square root of a number: ")
n = int(input("Enter a number: "))
print("Square root: ", n**0.5)
Output:
Square root of a number:
Enter a number: 64
Square root: 8.0
Code:
print("Area of a rectangle: ")
l = int(input("Enter length: "))
w = int(input("Enter width: "))
print("Area of a rectangle: ", l*w)
Output:
Area of a rectangle:
Enter length: 5
Enter width: 10
Area of a rectangle: 50
Code:
#Calculate Area and perimeter of a square
print("Calculate Area and perimeter of a square")
s = int(input("Enter the side: "))
print("Area: ", s*s)
print("Perimeter: ", 4 * s)
Output:
Calculate Area and perimeter of a square
Enter the side: 10
Area: 100
Perimeter: 40
Code:
#Calculate surface volume and area of a cylinder
print("Calculate surface volume and area of a cylinder")
h = int(input("Enter the height: "))
r = int(input("Enter the radius: "))
p = 3.14
print("Surface volume: ", (2*p*(r**2))+(2*p*r*h))
print("Volume: ", 2*p*(r**2)*h)
Output:
Calculate surface volume and area of a cylinder
Enter the height: 20
Enter the radius: 20
Surface volume: 5024.0
Volume: 50240.0
Code:
#Swap value of a variable
print("Swap value of a variable")
a = int(input("Enter the value of a: "))
b = int(input("Enter the value of b: "))
print("a = ", a)
print("b = ", b)
a, b = b, a
print("Value after swapping: ")
print("a = ", a)
print("b = ", b)
Output:
Swap value of a variable
Enter the value of a: 10
Enter the value of b: 5
a = 10
b= 5
Value after swapping:
a= 5
b = 10