Created
March 2, 2016 13:37
-
-
Save devpruthvi/5246ed369a614b1271e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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