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
#1
I wanted to write a little code that takes in a number. If the number is within a specified range, 0.0 to 1.0, no exception is thrown. But if it is outside the range, the program should prompt the user to input another number. I don't seem to be getting the prompting right when the exception happens. Instead of prompting the user for a new number, the code just fails. Please can anyone tell me what is wrong? The code is below.
Score = input('enter number between 0 and 1\n')
try : 
    Score = float(Score)
    if Score >= 0.0 and Score <=1.0 :
        print('correct number')
except:
    print('enter correct number')
Reply


Messages In This Thread
How to properly catch this exception - by Emekadavid - May-26-2020, 08:07 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