Reputation: 1
I am creating a program where I have to ask the user the same question, until they type "Stop"
My issue is,
The user input has to be a float, but still be able to recognize when the user types "stop" so it will stop asking the question . Im having difficulty doing this.
Upvotes: 0
Views: 3573
Reputation: 146
while True:
ans = input("Enter a number: ")
#Currently ans variable is a string.
#ans.lower() gives you a lowercase version of the string.
if ans.lower()=="stop":
break #This command breaks out of the while loop.
ans = float(ans)
#You can do what you need to do from here after you get your float.
Something like that I would say
Upvotes: 2