create a python program to calculate and print the area of the rectangle if the user enters 1 and print the area of a square if the user enters 2
Answers
def square():
s = float(input("Enter the side of the square: "))
print("Area of square =", s * s)
def rectangle():
le = float(input("Enter the length of the rectangle: "))
b = float(input("Enter the breadth of the rectangle: "))
print("Area of the rectangle =", le * b)
print("Press 1 to calculate Area of Square")
print("Press 2 to calculate Area of Rectangle")
f = int(input())
if f == 1:
square()
elif f == 2:
rectangle()
else:
print("Error 404: Wrong number pressed, cannot calculate area!")
Answer:
print('Calculate area of rectangle(1)')
print('Calculate area of square(2)')
choice = input("Your choice: ")
if choice == '1':
l = float(input("Enter length: "))
b = float(input("Enter breadth: "))
print("Area of rectangle = ", l*b)
else:
s = float(input("Enter side: "))
print("Area of square = ", s*s)
Explanation
this is for python