Python Forum
Error in Python script - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Error in Python script (/thread-27041.html)

Pages: 1 2


RE: Error in Python script - GOTO10 - May-25-2020

I agree with buran that your assignment is a bit too vague. It tells you to check the user's input, but not what to check for or or how to respond to invalid input.

I'd do something like this:
while True:
    try:
        temp = float(input("Enter your dog's age: "))
        break
    except ValueError:
        print('Invalid input! Please enter numbers only.')
This will keep prompting until the user enters something that can be converted to a float.