Test for multiple cases by placing if/else structures inside other if/else selection structures.
Here is a good example using pseudocode:
Print A for exam grades greater than or equal to 90, B for grades between 80 and 89, C for grades between 70 and 79, D for grades between 60 and 69 and F for all other grades.
if student's grade is greater than or equal to 90 print "A" else if student's grade is greater than or equal to 80 print "B" else if student's grade is greater than or equal to 70 print "C" else if student's grade is greater than or equal to 60 print "D" else print "F"
Here is a program snippet:
if grade >= 90: print ("A") else: if grade >= 80: print ("B") else: ...
It can also be written in this format:
if grade >= 90: print ("A") elif grade >= 80: print ("B") elif ...
Question:
1. Would the program still work as intended if the symbol >= was changed to <= ???
2. Can I write this program as follows?
if grade >= 90: print "A" if grade >= 80 and grade < 90: print "B" if grade >= 70 and grade < 80: print "C" if ...
3. Can you come up with a different way of writing the program and still in an efficient way?
Here is a flowchart for this structure:
Here is the starting of the flowchart for the grade assignment:
Assignments:
- Finish the flowchart
- Write a program, letter_grade_YI.py. This python program prompts the user for a numeric grade and prints the letter grade.
- Write an efficient program, many_letter_grades_YI.py as you discovered in the previous post. This python program prompts the user for a numeric grade and prints the letter grade. Additionally, it continues to prompt the user until the user says ānā to quit.
BEFORE YOU START CODING, DRAW THE FLOWCHART, and don’t start coding until I check it.