Skip to content

Instantly share code, notes, and snippets.

@AlexJWayne
Last active January 20, 2019 05:38
Show Gist options
  • Save AlexJWayne/f5e668f0ac30fba2793178f08460c50d to your computer and use it in GitHub Desktop.
Save AlexJWayne/f5e668f0ac30fba2793178f08460c50d to your computer and use it in GitHub Desktop.
# This program asks for a decimal value and calculates the corresponding
# letter grade.
# Ask the user for the score.
score_as_string = input('Please enter score between 0 and 1: ')
# Convert the string returned by input() to a number.
try:
score = float(score_as_string)
except:
print('Please enter a number')
quit()
# Ensure the score is between 0.0 and 1.0.
if score >= 0 and score <= 1:
print('Thanks! Your grade is...')
else:
print('Invalid Score')
quit()
# Print out the calculated grade.
if score >= 0.9:
print('A')
elif score >= 0.8:
print('B')
elif score >= 0.7:
print('C')
elif score >= 0.6:
print('D')
else:
print('F')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment