0

I wanna end the while loop when the user enters a value that is not either a float or integer. Why doesn’t this code work?

https://code.sololearn.com/cjHX20dQKZuA/?ref=app

12th Feb 2022, 2:51 PM
max
max - avatar
2 Answers
+ 5
input() returns string by default. So, type() always gives string type. You may try using try-except statements to handle this issue.
12th Feb 2022, 3:19 PM
Simba
Simba - avatar
+ 1
question=input("Yes or no: ") if question.upper()== "YES": while True: ans=input("What other number") if not ans.replace('.', '').isdigit(): break
12th Feb 2022, 6:03 PM
rodwynnejones
rodwynnejones - avatar