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="">=><=>=>
break
else:
print("This is not a correct size. Try Again!!")
return SizeOfPants
def return_size(SizeOfPants):
if 26 <= sizeofpants="">=><>
return "XXS"
elif 28 <= sizeofpants="">=><>
return "XS"
elif 30 <= sizeofpants="">=><>
return "S"
elif 32 <= sizeofpants="">=><>
return "M"
elif 36 <= sizeofpants="">=><>
return "L"
elif 38 <= sizeofpants="">=><>
return "XL"
elif 40 <= sizeofpants="">=><>
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()