0% found this document useful (0 votes)
4 views

Practical No3 python

The document contains a practical exercise for programming with various functions demonstrating arithmetic, logical, and bitwise operations. It includes code snippets for converting currencies, calculating data sizes, finding square roots, and determining areas and volumes of geometric shapes. Each exercise prompts user input and displays the output based on the calculations performed.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Practical No3 python

The document contains a practical exercise for programming with various functions demonstrating arithmetic, logical, and bitwise operations. It includes code snippets for converting currencies, calculating data sizes, finding square roots, and determining areas and volumes of geometric shapes. Each exercise prompts user input and displays the output based on the calculations performed.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical No:-3

Name=Shweta Chavan Patil Roll No:-3207

• Arithmetic Operators

• Logical Operators

• Bitwise Operators
Exercise:-
1.
def convert_usd_to_inr(usd):
conversion_rate = 82.7 # 1 USD = 82.7 INR (as of the time of writing this)
inr = usd * conversion_rate
return inr
usd = float(input("Enter the amount in U.S. dollars: "))
inr = convert_usd_to_inr(usd)
print(f"{usd} U.S. dollars is equal to {inr} Indian Rupees.")
output:-

2.
def convert_bits(bits):
bytes_ = bits / 8
megabytes = bytes_ / (1024 ** 2)
gigabytes = bytes_ / (1024 ** 3)
terabytes = bytes_ / (1024 ** 4)
return megabytes, gigabytes, terabytes
bits = int(input("Enter the number of bits: "))
mb, gb, tb = convert_bits(bits)
print(f"Megabytes: {mb:.6f} MB")
print(f"Gigabytes: {gb:.6f} GB")
print(f"Terabytes: {tb:.6f} TB")
Output:-

3.
import math
def find_square_root(num):
return math.sqrt(num)
num = float(input("Enter a number: "))
result = find_square_root(num)
print(f"Square root of {num} is {result:.6f}")
Output:-
4.
def rectangle_area(length, width):
return length * width
length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: ")
area = rectangle_area(length, width)
print(f"Area of the rectangle: {area:.2f} square units")
Output:-

5.
def square_properties(side):
area = side * side
perimeter = 4 * side
return area, perimeter
side = float(input("Enter the side length of the square: "))
area, perimeter = square_properties(side)
print(f"Area of the square: {area:.2f} square units")
print(f"Perimeter of the square: {perimeter:.2f} units")
Output:-

6.
import math
def cylinder_properties(radius, height):
surface_area = 2 * math.pi * radius * (radius + height)
volume = math.pi * radius**2 * height
return surface_area, volume
radius = float(input("Enter the radius of the cylinder: "))
height = float(input("Enter the height of the cylinder: "))
surface_area, volume = cylinder_properties(radius, height)
print(f"Surface Area of the cylinder: {surface_area:.2f} square units")
print(f"Volume of the cylinder: {volume:.2f} cubic units")
Output:-
7.
def swap_values(a, b):
a, b = b, a
return a, b
x = input("Enter the first value: ")
y = input("Enter the second value: ")
x, y = swap_values(x, y)
print(f"After swapping, first value: {x}")
print(f"After swapping, second value: {y}")
Output:-

You might also like