I am working on a homework assignment that a user will input a grade percentage and it will output a letter grade. My issue is that I would like to restrict the user to only the number keys and a decimal point. If the user inputs anything else they will be prompted with an error message and will have a chance to input again. Here is my code that will work without the decimal, but I need the int to be float. Please help! Any feedback will be greatly appreciated!!
def percentLoop()
while True:
a = input('Enter a percent: ')
try:
number = int(a)
if (0< number <= 100):
return number
else:
print ('Enter a percent between 0 and 100.')
except:
print ('Please enter a percent between 0 and 100.')
Thanks for looking at what I have.