Skip to content

Instantly share code, notes, and snippets.

@devpruthvi
Created March 2, 2016 13:37
Show Gist options
  • Save devpruthvi/5246ed369a614b1271e0 to your computer and use it in GitHub Desktop.
Save devpruthvi/5246ed369a614b1271e0 to your computer and use it in GitHub Desktop.
import numbers
def getNumber(s):
try:
return int(s)
except ValueError:
return float(s)
flag = True
while flag:
try:
score = raw_input('Enter score: ')
if not isinstance(float(score), numbers.Real):
raise Exception
else:
score = getNumber(score)
if score >= 0.9:
grade = 'A'
elif score >= 0.8:
grade = 'B'
elif score >= 0.7:
grade = 'C'
print('Your grade is ' + grade)
except:
print('Only numbers are allowed')
inp = raw_input('Do you want to continue?\n>')
if inp == "no":
print('You have quit the program')
flag = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment