Question

In: Computer Science

---- Python CIMP 8A Code Lab 4 Write a program that asks the user to enter...

---- Python

CIMP 8A

Code Lab 4

Write a program that asks the user to enter 5 test scores. The program will display a letter grade for each test score and an average grade for the test scores entered. The program will write the student name and average test score to a text file (“studentgrades.txt”). Three functions are needed for this program.

def letter_grade( test_score)

Test Score

Letter Grade

90-100

A

80-89

B

70-79

C

60-69

D

Below 60

F

return letter grade

def calculate_average_grade( test1, test2, test3, test4, test5)

add 5 test scores together with a sum

divide the sum by 5 for an average

return the average

def main() Starting function

            In a loop for 4 students

Enter student name

                        In a loop for 5 test scores

enter test score

                                    call letter_grade(test_score)

                                    display testscore and letter grade

                        After loop

                                    call calculate_average_grade (test1, test2, test3, test4, test5)

                                    display average test score

                                    write to output file –

                                                            name,

average test score and

letter grade for average test score

           

Solutions

Expert Solution

Code Screenshot :

Executable Code:

#Function to find the letter grade
def letter_grade(test_score):
   if test_score <=100 and test_score>=90:
       return 'A'
   if test_score <=89 and test_score>=80:
       return 'B'
   if test_score <=79 and test_score>=70:
       return 'C'
   if test_score <=69 and test_score>=60:
       return 'D'
   if test_score <60:
       return 'F'

#Function to calculate the average
def calculate_average_grade(test1, test2, test3, test4, test5):
   sum= test1+test2+test3+test4+test5
   #Calculate average
   average = sum/5
   #Return result
   return average


#Main Function
def main():
   #Declaring the required variables
   test1=0
   test2=0
   test3=0
   test4=0
   test5=0
   #Prompting the user for name
   name = input("Please enter your name: ")
   for i in range(5):
       #Prompting the user for test scores
       test_score = int(input("Enter test "+str(i+1)+" score: "))
       print("Test Score :",test_score,"Letter Grade:",letter_grade(test_score))
       if i==0:
           test1=test_score
       elif i==1:
           test2=test_score
       elif i==2:
           test3=test_score
       elif i==3:
           test4=test_score
       elif i==4:
           test5=test_score
   #Find the average
   average = calculate_average_grade(test1, test2, test3, test4, test5)
   #Display the average
   print("Average: ",average)
   #Open file
   with open("studentgrades.txt","w") as f:
       #Write name average and lettergrade to file
       f.write(name)
       f.write("\nAverage Test Score ="+str(average))
       f.write("\nLetter Grade ="+str(letter_grade(test_score)))

#Function call to main
main()

Sample Output :

Please comment below if you have any queries.
Please do give a thumbs up if you liked the answer thanks :)


Related Solutions

Please write in Python code please: Write a program that asks the user to enter 5...
Please write in Python code please: Write a program that asks the user to enter 5 test scores between 0 and 100. The program should display a letter grade for each score and the average test score. You will need to write the following functions, including main: calc_average – The function should accept a list of 5 test scores as an input argument, and return the average of the scores determine_grade – The function should accept a test score as...
In Python write a program that asks the user to enter the monthly costs for the...
In Python write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance the program should then display the total monthly cost of these expenses, and the total annual cost of these expenses. your program MUST have BOTH a main function AND a function named calcExpenses to calculate the expenses. DO NOT display the expenses inside of the calcExpenses function!!...
Python. Write a code that asks the user to enter a string. Count the number of...
Python. Write a code that asks the user to enter a string. Count the number of different vowels ( a, e, i, o, u) that are in the string and print out the total. You may need to write 5 different if statements, one for each vowel. Enter a string: mouse mouse has 3 different vowels
Write a program in PYTHON, using a while loop, that asks the user to enter the...
Write a program in PYTHON, using a while loop, that asks the user to enter the amount that they have budgeted for the month. The program should then prompt the user to enter their expenses for the month. The program should keep a running total. Once the user has finished entering their expenses the program should then display if the user is over or under budget. The output should display the monthly budget, the total expenses and whether the user...
(IN PYTHON) Write a program that asks the user repeatedly to enter a student's score or...
(IN PYTHON) Write a program that asks the user repeatedly to enter a student's score or enter -1 to stop. When finished entering all the scores, the program should display the number of scores entered, the sum of the scores, the mean, the lowest and the highest score. (IN PYTHON)
CODE IN PYTHON 1. Write a program that asks the user for the number of slices...
CODE IN PYTHON 1. Write a program that asks the user for the number of slices of pizza they want to order and displays the total number of dollar bills they owe given pizza costs 3 dollars a slice.  Note: You may print the value an integer value. 2. Assume that y, a and b have already been defined, display the value of x: x =   ya+b    3. The variable start_tees refers to the number of UD T-shirts at the start...
PYTHON: Write a program that asks the user to enter a 10-character telephone number in the...
PYTHON: Write a program that asks the user to enter a 10-character telephone number in the format XXX-XXX-XXXX. The application should display the telephone number with any alphabetic characters that appeared in the original translated to their numeric equivalent. For example, if the user enters 555-GET-FOOD, the application should display 555-438-3663. This is my code, but I cannot figure out where to go from here. #set new number new_number = "" #split number split_num = phone.split("-") for char in split_num[1:2]:...
Write a Python program that asks the user to enter a student's name and 8 numeric...
Write a Python program that asks the user to enter a student's name and 8 numeric tests scores (out of 100 for each test). The name will be a local variable. The program should display a letter grade for each score, and the average test score, along with the student's name. Write the following functions in the program: calc_average - this function should accept 8 test scores as arguments and return the average of the scores per student determine_grade -...
Write a python program which asks the user to enter a positive number that is greater...
Write a python program which asks the user to enter a positive number that is greater than 30 called, “num2” and then does the following: o 1) Print all numbers between 1 and “num2” that are divisible by 2 and 3. o 2) Print all numbers between 1 and “num2” that are either divisible by 6 or 7. o 3) Print all numbers between 1 and “num3” that is not divisible by 5
PYTHON Write a program that asks the user to enter a student's name and 8 numeric...
PYTHON Write a program that asks the user to enter a student's name and 8 numeric assignment scores (out of 100 for each assignment). The program should output the student's name, a letter grade for each assignment score, and a cumulative average for all the assignments. Please note, there are 12 students in the class so your program will need to be able to either accept data for 12 students or loop 12 times in order to process all the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT