Skip to content

Instantly share code, notes, and snippets.

@afrendeiro
Last active January 4, 2016 19:19
Show Gist options
  • Save afrendeiro/8666618 to your computer and use it in GitHub Desktop.
Save afrendeiro/8666618 to your computer and use it in GitHub Desktop.
Reads in a score (1-100) and prints out the corresponding character (grade). Done without the if control structure.
#Create a method that reads in a score (1-100) and prints out the corresponding character (grade).
#Assume the following grade assignment: 'A' = 100-81 points, 'B' = 80-61 points, 'C' = 60-41 points, 'D' = 40-21 points and 'E' = 20-1 points.
# Don't use the "if" control structure
score = 1
scale = [range(81,100), range(61,80), range(41,60), range(21,40), range(1,20)]
grades = ["A", "B", "C", "D", "E"]
for grade in range(0, len(scale)):
while score in scale[grade]:
print grades[grade]
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment