Please fix of couple things in the code below. A couple of things. The input value is the waist size; the pant size is what the program is going to determine. The name valid_input is too generic. The name of the function should reflect what it does; also, start the name of the function with an action verb. For example, read_waist_size We can simplify the reading with the form : Read waist size WHILE waist size is not in the right range DO Show error message Read waist size again Simpler. By the way, the error message should let the user know how not to make the same mistake again. Something like, “This is not a correct size. Enter a value between 26 and 42.” is more helpful. def valid_input(): while True: SizeOfPants = int(input("What pants size you are looking for: ")) if 26 <= SizeOfPants <= 42: break else: print("This is not a correct size. Try Again!!") return SizeOfPants def return_size(SizeOfPants): if 26 <= SizeOfPants < 28: return "XXS" elif 28 <= SizeOfPants < 30: return "XS" elif 30 <= SizeOfPants < 32: return "S" elif 32 <= SizeOfPants < 34: return "M" elif 36 <= SizeOfPants < 38: return "L" elif 38 <= SizeOfPants < 40: return "XL" elif 40 <= SizeOfPants < 42: return "XXL" else: return "No size Available." def main(): print("Please choose size of the pants between 26(XS) inches to 42(XXL) inches") SizeOfPants = valid_input() size = return_size(SizeOfPants) print(f"Your size is {size}") main()
Please fix of couple things in the code below.
A couple of things.
-
The input value is the waist size; the pant size is what the program is going to determine.
-
The name valid_input is too generic. The name of the function should reflect what it does; also, start the name of the function with an action verb. For example, read_waist_size
-
We can simplify the reading with the form :
Read waist size WHILE waist size is not in the right range DO Show error message Read waist size again
Simpler. By the way, the error message should let the user know how not to make the same mistake again. Something like, “This is not a correct size. Enter a value between 26 and 42.” is more helpful.
def valid_input():
while True:
SizeOfPants = int(input("What pants size you are looking for: "))
if 26 <= SizeOfPants <= 42:
break
else:
print("This is not a correct size. Try Again!!")
return SizeOfPants
def return_size(SizeOfPants):
if 26 <= SizeOfPants < 28:
return "XXS"
elif 28 <= SizeOfPants < 30:
return "XS"
elif 30 <= SizeOfPants < 32:
return "S"
elif 32 <= SizeOfPants < 34:
return "M"
elif 36 <= SizeOfPants < 38:
return "L"
elif 38 <= SizeOfPants < 40:
return "XL"
elif 40 <= SizeOfPants < 42:
return "XXL"
else:
return "No size Available."
def main():
print("Please choose size of the pants between 26(XS) inches to 42(XXL) inches")
SizeOfPants = valid_input()
size = return_size(SizeOfPants)
print(f"Your size is {size}")
main()
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images