Assignment-1 Solutions
Assignment-1 Solutions
Write a program to read two integers and perform arithmetic operations on them
(addition, subtraction, multiplication and division).
def arithmetic_operations(a, b):
addition = a + b
subtraction = a - b
multiplication = a * b
division = a / b if b != 0 else 'Undefined (Division by zero)'
return addition, subtraction, multiplication, division
results = arithmetic_operations(a, b)
print(f"Addition: {results[0]}")
print(f"Subtraction: {results[1]}")
print(f"Multiplication: {results[2]}")
print(f"Division: {results[3]}")
2. Write a program to read the marks of three subjects and find the average of them.
def average_marks(mark1, mark2, mark3):
return (mark1 + mark2 + mark3) / 3
surface_area = surface_area_prism(a, b, c)
print(f"The surface area of the prism is: {surface_area}")
5. A plane travels 395,000 meters in 9000 seconds. Write a program to find the speed of the
plane (Speed = Distance / Time).
def speed(distance, time):
return distance / time
6. You need to empty out the rectangular swimming pool which is 12 meters long, 7 meters
wide and 2 meter depth. You have a pump which can move 17 cubic meters of water in an
hour. Write a program to find how long it will take to empty your pool? (Volume = l * w * h,
and flow = volume/time).
def time_to_empty_pool(length, width, depth, flow_rate):
volume = length * width * depth
time = volume / flow_rate
return time
length = 12 # meters
width = 7 # meters
depth = 2 # meters
flow_rate = 17 # cubic meters per hour
seconds = seconds_in_day()
print(f"There are {seconds} seconds in a day")
9. A car starts from a stoplight and is traveling with a velocity of 10 m/sec east in 20
seconds. Write a program to find the acceleration of the car. (acc = (vfinal−vinitial)/ time).
def acceleration(v_initial, v_final, time):
return (v_final - v_initial) / time
v_initial = 0 # m/s
v_final = 10 # m/s
time = 20 # seconds