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

Prac 3

The document contains practical exercises on Python programming, focusing on arithmetic, logical, and bitwise operators. It includes code examples for converting currencies, calculating areas, and performing mathematical operations. Each exercise is accompanied by sample code and expected output.

Uploaded by

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

Prac 3

The document contains practical exercises on Python programming, focusing on arithmetic, logical, and bitwise operators. It includes code examples for converting currencies, calculating areas, and performing mathematical operations. Each exercise is accompanied by sample code and expected output.

Uploaded by

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

dd

NAME: SUMEDH SANJAY RAUT


CLASS: CO6I(A)
ROLL NO: 532
SUBJECT: PYTHON(22616)

PRACTICAL NO: 3

*Arithmetic Operators In Python


Code:
a=45
b=15
print("***Arithmetic Operators IN Python\n")
print("Addition:",a+b)
print("Subtraction:",a-b)
print("Division:",a/b)
print("Modulus:",a%b)
print("Exponent",a**b)
print("Floor Division",a//b)
Output:
dd

*Logical Operators In Python


Code:
a=45
b=15
print("***Logical Operators In Python***\n")
print("Logical AND:",a>b)
print("Logical OR:",a==b)
print("Logical NOT:",a>b)

Output:

*Bitwise Operators In Python


Code:
a=13
b=19
print("***Bitwise Operators In Python***\n")
print("Bitwise AND:",a&b)
print("Bitwise OR:",a|b)
print("Bitwise NOT:",~b)
print("Bitwise XOR:",a^b)
print("Bitwise Right shift:",a>>b)
print("Bitwise Left shift:",a<<b)
Output:
dd

X. Exercise

1. Write a program to convert U.S. dollars to Indian rupees.


Code:

print("Conversion of US dollar to Indian rupees")


USDollar=int(input("Enter a Dollar:"))
inr=USDollar*71.27
print("INR=",inr)
Output:

2. Write a program to convert bits to Megabytes, Gigabytes and Terabytes.


Code:

bits = float(input("Enter the number of bits: "))

BITS_IN_BYTE = 8
BYTES_IN_MB = 1024 * 1024
BYTES_IN_GB = BYTES_IN_MB * 1024
BYTES_IN_TB = BYTES_IN_GB * 1024

bytes = bits / BITS_IN_BYTE

megabytes = bytes / BYTES_IN_MB


gigabytes = bytes / BYTES_IN_GB
terabytes = bytes / BYTES_IN_TB
print(f"{bits} bits is equal to:")
print(f"{megabytes:.6f} Megabytes (MB)")
print(f"{gigabytes:.6f} Gigabytes (GB)")
print(f"{terabytes:.6f} Terabytes (TB)")
dd

Output:

3. Write a program to find the square root of a number


Code:
num = float(input("Enter a number: "))

if num < 0:
print("Square root is not defined for negative numbers.")
else:
sqrt = num ** 0.5
print(f"The square root of {num} is {sqrt:.2f}")

Output:
dd

4. Write a program to find the area of Rectangle


Code:

length = float(input("Enter the length of the rectangle: "))


breadth = float(input("Enter the breadth of the rectangle: "))

area = length * breadth

print(f"The area of the rectangle is {area:.2f} square units.")


Output:

5. Write a program to calculate area and perimeter of the square


Code:
side = float(input("Enter the side length of the square: "))

area = side ** 2
perimeter = 4 * side

print(f"The area of the square is {area:.2f} square units.")


print(f"The perimeter of the square is {perimeter:.2f} units.")

Output:
dd

6. Write a program to calculate surface volume and area of a cylinder.


Code:
import math

radius = float(input("Enter the radius of the cylinder: "))


height = float(input("Enter the height of the cylinder: "))

surface_area = 2 * math.pi * radius * (radius + height)

volume = math.pi * radius**2 * height

print(f"The surface area of the cylinder is {surface_area:.2f} square units.")


print(f"The volume of the cylinder is {volume:.2f} cubic units.")

Output:

7. Write a program to swap the value of two variables


Code:
a = input("Enter the value of a: ")
b = input("Enter the value of b: ")

a, b = b, a

print(f"After swapping:")
print(f"Value of a: {a}")
print(f"Value of b: {b}")
Output:

You might also like