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
#8
This may get you closer
while True : 
    score = input('number btw 0 and 1\n')
    try :
        score = float(score)
        if score<=0 or score>=1:
            raise ValueError
    except ValueError:
        print('not number, at least not in range')
The part we haven't answered is how to raise an error. This is how. With it you will get an error to trigger the except block whether the person enters "5" or "a".
Reply


Messages In This Thread
RE: How to properly catch this exception - by buran - May-26-2020, 10:42 AM
RE: How to properly catch this exception - by jefsummers - May-26-2020, 09:00 PM
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