Lecture 11/17/2026
This commit is contained in:
parent
07b9e54bf0
commit
bf3265103a
44 changed files with 1195 additions and 3 deletions
30
lecture20261117/while/rectangle2.py
Normal file
30
lecture20261117/while/rectangle2.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
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))
|
||||
Loading…
Add table
Add a link
Reference in a new issue