An error occurs when trying to convert a Python 3 string to an integer if a non-numeric character exists

Asked 2 years ago, Updated 2 years ago, 13 views

While(correct_count) I need to fix this print("Input Error")

When you press enter without a fixed income power

It goes like this.What should I do?

python

2022-09-21 19:39

1 Answers

If you read it carefully, a ValueError is occurring because you are trying to convert a string to a number. You can deal with ValueError like this.

try: 
    int("a")
except ValueError:
    print ("Please enter a number")


2022-09-21 19:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.