Python Forum
Error in Python script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in Python script
#11
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Re-write BASH script to Python script popi75 5 2,446 Apr-30-2021, 03:52 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020