0% found this document useful (0 votes)
29 views3 pages

Assignment-1 Solutions

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)
29 views3 pages

Assignment-1 Solutions

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/ 3

1.

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

a = int(input("Enter the first integer: "))


b = int(input("Enter the second integer: "))

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

mark1 = float(input("Enter the marks for subject 1: "))


mark2 = float(input("Enter the marks for subject 2: "))
mark3 = float(input("Enter the marks for subject 3: "))

average = average_marks(mark1, mark2, mark3)


print(f"The average marks are: {average}")

3. Write a program to convert kilogram into pound.


def kg_to_lb(kg):
return kg * 2.20462

kg = float(input("Enter the weight in kilograms: "))


lb = kg_to_lb(kg)
print(f"{kg} kilograms is equal to {lb} pounds")
4. Surface area of a prism can be calculated if the lengths of the three sides are known.
Write a program that takes the sides as input (read it as integer) and prints the surface area
of the prism (Surface Area = 2ab + 2bc + 2ca).
def surface_area_prism(a, b, c):
return 2 * (a * b + b * c + c * a)

a = int(input("Enter the length of side a: "))


b = int(input("Enter the length of side b: "))
c = int(input("Enter the length of side c: "))

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

distance = 395000 # meters


time = 9000 # seconds

plane_speed = speed(distance, time)


print(f"The speed of the plane is: {plane_speed} m/s")

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

time_needed = time_to_empty_pool(length, width, depth, flow_rate)


print(f"The time needed to empty the pool is: {time_needed} hours")
7. Write a program to convert temperature from centigrade (read it as float value) to
Fahrenheit.
def celsius_to_fahrenheit(celsius):
return (celsius * 9/5) + 32

celsius = float(input("Enter the temperature in centigrade: "))


fahrenheit = celsius_to_fahrenheit(celsius)
print(f"{celsius}°C is equal to {fahrenheit}°F")

8. Write a program that calculates the number of seconds in a day.


def seconds_in_day():
return 24 * 60 * 60

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

acc = acceleration(v_initial, v_final, time)


print(f"The acceleration of the car is: {acc} m/s²")

You might also like