I am doing my homework and am having trouble on a certain problem.
4) A certain CS professor gives 100-point exams that are graded on the scale 90-100:A, 80-89:B, 70-79:C, 60-69:'D, <60:F. Write a program that accepts an exam score as input and prints out the corresponding grade.
We have not learned any kind of an "if" statement in my class yet. I did a problem before this one that was similar:
3) A certain CS professor gives 5-point quizzes that are graded on the scale 5-A, 4-B, 3-C, 2-D, 1-F, 0-F. Write a program that accepts a quiz score as an input and prints out the corresponding grade.
For this, I just used a list.
def main(): grade = raw_input("Enter the student's grade: ") grades = ["F", "F", "D", "C", "B", "A"] final = grades[int(grade)] print final main()
I know I could do simultaneous assignment for each number through 100, but I know there is a better / easier way. I think I need to use a loop (we know the for loop) somehow or go back to the list. Also, I believe I would need to incorporate range(). I am drawing a blank. How can I go about solving my problem without using any kind of if statements?