Students average on Quiz Scores
Problem:
You have been hired by a teacher to create a program that will tell the student what their average and letter grade is for a class based on 5 quiz grades.
Instructions:
Use the following algorithm as your guide to creating this program.
MUST use a loop also to ask for the 5 quiz grades
MUST store the grades in a list
MUST use the sum and len functions with your list to find the average
Make sure that you use exception handling so that if the user tries to enter a word like ninety instead of a number like 90, for example, it will tell them what they did wrong nicely instead of just crashing.
#Define the main function
#Create constants to store letter grades A - F associated with their lowest numeric value (like A = 90)
#Declare and initialize string variable to store name
#Declare and initialize real variables for a quiz grade, and average
#and a whole var for the number of times taking a course
#Create a list that will store 5 quiz grades
#display an introduction
#prompt for users name
#prompt the user for the number of times they have attempted this course (1, 2, or 3)
#using a loop prompt for a quiz grade 5 times adding each grade to your list (use their name in the prompt and display it with a cap 1st letter)
#calculate the average of the 5 grades
#use a decision to display a letter grade based on the average
#if the average is 90 or higher and it is their first attempt at the class display "Your average is ____ You earned an A, GREAT JOB!"
#if the average is 90 or higher and it is their second attempt at the class
#display "Your average is ____. You earned an A, aren't you glad you gave it a second try!"
#if the average is 90 or higher and it is their third attempt at the class
#display "Your average is ____. You earned an A, Third time is a charm!"
#if the average is between 80 and 89 and it is their first attempt at the class display "Your average is ____. You earned a B, Good Job!"
#if the average is between 80 and 89 and it is their second attempt at the class
#display "Your average is ____. You earned a B, aren't you glad you gave it a second try!"
#if the average is between 80 and 89 and it is the third attempt at the class
#display "Your average is ____. You earned a B, Third time is a charm!"
#if the average is between 70 and 79 and it is their first attempt at the class
#display "Your average is ____. You earned a C, please keep studying to get even better!"
#if the average is between 70 and 79 and it is their second attempt at the class
#display "Your average is ____. You earned a C, aren't you glad you gave it a second try!"
#if the average is between 70 and 79 and it is their third attempt at the class
#display "Your average is ____. You earned a C, You Pass - Third time is a charm!!"
#if the average is between 60 and 69 and it is their first attempt at the course
#display "Your average is ____. You earned a D, it's passing but will not transfer! I would take it again"
#if the average is between 60 and 69 and it is their second attempt at the course display
#"Your average is ____. You earned a D, it's passing but will not transfer!, I would take it again but you will have to pay more this time"
#if the average is between 60 and 69 and it is their third attempt at the course
#display "Your average is ____. You earned a D, it's passing but will not transfer! I'm afraid you have used all your attempts at this class and cannot re-take it!"
#if the average is under 60 it is their first attempt at the course
#display "Your average is ____. You earned an F, Please try this class a second time!"
#if the average is under 60 it is their second attempt at the course
#display "Your average is ____. You earned an F, Please try this class a third time, but you will pay more this time!"
#if the average is under 60 it is their third attempt at the course
#display "Your average is ____. You earned an F, I'm afraid you have used all your attempts at this class and cannot re-take it!"
#display outro (use their name in the outro and display it with a cap 1st letter) thanking them for using the program.
Solution:
def main():
A = 90
B = 80
C = 70
D = 60
grades = []
average = 0
name = input("Please enter your name: ")
name = name.lower()
name = name[0].upper() + name[1:]
attempts = int(input("How many times have you attended the course? "))
for i in range(5):
grade = int(input("Enter your grade " + str(i+1) + " : "))
grades.append(grade)
average += grade
average = average/5
if average >= A and attempts == 1:
print("Your average is " + str(average) + " You earned an A, GREAT JOB!")
elif average >= A and attempts == 2:
print("Your average is " + str(average) + " . You earned an A, aren't you glad you gave it a second try!")
elif average >= A and attempts == 3:
print("Your average is " + str(average) + " . You earned an A, Third time is a charm!")
elif average >= B and attempts == 1:
print("Your average is " + str(average) + " . You earned an B, Good Job!")
elif average >= B and attempts == 2:
print("Your average is " + str(average) + " . You earned an B, aren't you glad you gave it a second try!")
elif average >= B and attempts == 3:
print("Your average is " + str(average) + " . You earned an B, Third time is a charm!")
elif average >= C and attempts == 1:
print("Your average is " + str(average) + " . You earned an C, please keep studying to get even better!")
elif average >= C and attempts == 2:
print("Your average is " + str(average) + " . You earned an C, aren't you glad you gave it a second try!")
elif average >= C and attempts == 3:
print("Your average is " + str(average) + " . You earned an C, You Pass - Third time is a charm!!")
elif average >= D and attempts == 1:
print("Your average is " + str(average) + " . You earned an D, it's passing but will not transfer! I would take it again")
elif average >= D and attempts == 2:
print("Your average is " + str(average) + " . You earned an D, it's passing but will not transfer!, I would take it again but you will have to pay more this time")
elif average >= D and attempts == 3:
print("Your average is " + str(average) + " . You earned an D, it's passing but will not transfer! I'm afraid you have used all your attempts at this class and cannot re-take it!")
elif average < D and attempts == 1:
print("Your average is " + str(average) + " . You earned an F, Please try this class a second time!")
elif average < D and attempts == 2:
print("Your average is " + str(average) + " . You earned an F, Please try this class a third time, but you will pay more this time!")
elif average < D and attempts == 3:
print("Your average is " + str(average) + " . You earned an F, I'm afraid you have used all your attempts at this class and cannot re-take it!")
print("Thank you for using the program: " + name)
if __name__ == '__main__':
main()