Lab 2 Practice Problems
Lab 2 Practice Problems
● Write a program that takes the radius of a circle as input from the user and calculates the
area of the circle. (Formula: area = π * r^2, assume π = 3.14)
● Write a program that asks the user for the prices of three grocery items and calculates
the total bill.
● Write a program that takes the length and width of a rectangle as input and calculates
the perimeter. (Formula: perimeter = 2 * (length + width))
● Write a program that takes an input number of minutes and converts it into hours and
minutes. For example, 130 minutes is 2 hours and 10 minutes.
● Write a program that takes the user’s weight in kilograms and height in meters and
calculates their BMI. (Formula: BMI = weight / (height^2))
For the following codes, try to think about the output of the code without
executing it and then try executing it to see if your answer was correct
Code 1:
price1 = 10
price2 = 5
total = price1 + price2
print("Total Price:", total)
Code 2:
length = 12
width = 4
perimeter = 2 * (length + width)
print("Perimeter:", perimeter)
Code 3:
hours = 2
minutes = hours * 60 + 30
print("Total Minutes:", minutes)
Code 4:
weight = 70
height = 1.75
bmi = weight / (height ** 2)
print("BMI:", bmi)
Code 5:
radius = 5
pi = 3.14
area = pi * radius ** 2
print("Area of Circle:", area)
Following code snippets has some missing lines, try to read comments to
understand how the code is supposed to work and complete the code by
adding missing code.
Code 1:
Code 2:
Code 3:
Code 4:
# Program to calculate the discounted price of an item
original_price = float(input("Enter the original price: "))
discount_percent = float(input("Enter the discount percentage: "))
# Missing code to calculate and display the discounted price (Formula: discounted_price =
original_price - (original_price * discount_percent / 100))
Code 5: