2021-08-29

How to make a specific string work in a try-except block?

I don't want to make the user be able to enter anything other than numbers as the input for the "number" variable, except for the string "done".

Is it possible to somehow make an exception to the rules of the try-except block, and make the user be able to write "done" to break the while loop, while still keeping the current functionality? Or should I just try something different to make that work?

while number != "done":
    try:
        number = float(input("Enter a number: ")) #The user should be able to write "done" here as well
    except ValueError:
        print("not a number!")
        continue


from Recent Questions - Stack Overflow https://ift.tt/38mWfOU
https://ift.tt/eA8V8J

No comments:

Post a Comment