2026fa_cse160/lecture20261117/while/rectangle2.py
2026-11-17 12:30:27 -05:00

30 lines
822 B
Python

print("Calculate the area of a rectangle")
counter = 3
length = float(input("Enter the length of one side: "))
while(length <= 0):
print("ERROR: The length must be greater than zero")
print("You entered {}".format(length))
counter = counter - 1
if(counter <= 0):
print("Too many tries. Program exiting.")
exit(-1)
length = float(input("Enter the length of one side: "))
runFlag = True
counter = 3
while(runFlag):
width = float(input("Enter the width of the other side: "))
if(width <= 0):
print("ERROR: The width must be greater than zero")
print("You entered {}".format(width))
counter = counter - 1
if(counter <= 0):
print("Too many tries. Program exiting.")
exit(-1)
else:
runFlag = False
area = length * width
print("The area is {}".format(area))