0% found this document useful (0 votes)
8 views4 pages

PWP PR 3

The document contains various Python code snippets demonstrating the use of operators, conversions, and calculations. It includes examples of arithmetic, logical, and bitwise operations, as well as functions for converting currencies, calculating areas, and swapping variable values. Each code section is followed by sample output for clarity.

Uploaded by

arqamqazi549
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

PWP PR 3

The document contains various Python code snippets demonstrating the use of operators, conversions, and calculations. It includes examples of arithmetic, logical, and bitwise operations, as well as functions for converting currencies, calculating areas, and swapping variable values. Each code section is followed by sample output for clarity.

Uploaded by

arqamqazi549
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

#Name: Qazi Arqam

#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))

print('(2==2) or (9<20) = ', (2==2) or (9<20))


print('(3!=3) or (9>20) = ', (3!=3) or (9>20))

print('not(8>2) = ', not(8>2))


print('not(2>10) = ', not(2>10))

#Bitwise Operator
a = 10
b=4

print("a&b = ", a&b)


print('a|b = ', a|b)
print('~a = ', ~a)
print('a^b = ', a^b)
print("a<<2 = ", a<<2)
print("a>>2 = ", a>>2)

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

You might also like