Python Forum
How to properly catch this exception
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to properly catch this exception
#2
The way you use except is wrong - The except block lets you handle the error. So for example
try:
  print(x)
except NameError:
  print("Variable x is not defined")
except:
  print("Something else went wrong")
Here, the variable x is not defined, and therefore, a Nameerror will come like
Error:
Variable x not defined
like that
here, even if the input is greater than 1, an error will not come.
You will have to use a while loop like
while Score > 1:
    Score = input('enter number between 0 and 1\n')
Then print your rest of the code. The while loop will work as long as your score is greater than 1. When it becomes less than 1, it will automatically break
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply


Messages In This Thread
RE: How to properly catch this exception - by pyzyx3qwerty - May-26-2020, 08:51 AM
RE: How to properly catch this exception - by buran - May-26-2020, 10:42 AM
RE: How to properly catch this exception - by buran - May-27-2020, 08:00 AM

Forum Jump:

User Panel Messages

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