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. There are 12 students in the class.
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 - this function should accept a test score average as an argument and return a letter grade for the score based on the following grading scale:
90-100 A
80-89 B
70-79 C
60-69 D
Below 60 F

Respuesta :

Answer:

The program doesn't make use of comments (See Explanation)

Also the source code is attached as image to enable you see the proper format and indexing of the source code

The program using python is as follows

def calc_average(name):

   score = []

   sum = 0

   for j in range(8):

       inp = int(input("Test Score"+str(j+1)+": "))

       score.append(inp)

       sum = sum + inp

       if inp>=90 and inp<=100:

           print("A")

       elif inp>=80 and inp<90:

           print("B")

       elif inp>=70 and inp<80:

           print("C")

       elif inp>=60 and inp<70:

           print("D")

       else:

           print("F")

   avg = sum/8

   print("Result Details of "+name)

   print("Average Score: "+str(avg))

   return avg

def determine_grade(result):

   if float(result) >= 90.0 and float(result) <= 100.0:

       print("Letter Grade: A")

   elif float(result) >= 80.0 and float(result) <90.0:

       print("Letter Grade: B")

   elif float(result) >= 70.0 and float(result) < 80.0:

       print("Letter Grade: C")

   elif float(result) >= 60.0 and float(result) < 70.0:

       print("Letter Grade: D")

   else:

       print("Letter Grade: F")

   print(" ")

for i in range(2):

   name = input("Student Name: ")

   result = calc_average(name)

   determine_grade(result)

Explanation:

def calc_average(name):  -> Declares the function calc_average(name); It accepts local variable name from the main function

   score = []

-> Initialize an empty list to hold test scores

   sum = 0

-> Initialize sum of scores to 0

   for j in range(8):

-> Iterate from test score 1 to 8

       inp = int(input("Test Score"+str(j+1)+": "))

-> This line accepts test score from the user

       score.append(inp)

-> The user input is then saved in a lisy

       sum = sum + inp

-> Add test scores

The following lines determine the letter grade of each test score      

if inp>=90 and inp<=100:

           print("A")

---

      else:

           print("F")

   avg = sum/8  -> Calculate average of the test score

The next two lines prints the name and average test score of the student

   print("Result Details of "+name)

   print("Average Score: "+str(avg))

   return avg

-> This line returns average to the main method

The following is the determine_grade method; it takes it parameter from the main method and it determines the letter grade depending on the calculated average

def determine_grade(result):

   if float(result) >= 90.0 and float(result) <= 100.0:

       print("Letter Grade: A")

   elif float(result) >= 80.0 and float(result) <90.0:

       print("Letter Grade: B")

   elif float(result) >= 70.0 and float(result) < 80.0:

       print("Letter Grade: C")

   elif float(result) >= 60.0 and float(result) < 70.0:

       print("Letter Grade: D")

   else:

       print("Letter Grade: F")

   print(" ")

for i in range(2):

-> This is the main method

   name = input("Student Name: ")  -> A local variable stores name of the student

   result = calc_average(name)  -> store average of scores in variable results

   determine_grade(result)-> Call the determine_grade function

Ver imagen MrRoyal
Ver imagen MrRoyal

In this exercise we have to use the computer language knowledge in python to write the code as:

the code is in the attached image.

In a more easy way we have that the code will be:

def calc_average(name):

  score = []

  sum = 0

  for j in range(8):

      inp = int(input("Test Score"+str(j+1)+": "))

      score.append(inp)

      sum = sum + inp

      if inp>=90 and inp<=100:

          print("A")

      elif inp>=80 and inp<90:

          print("B")

      elif inp>=70 and inp<80:

          print("C")

      elif inp>=60 and inp<70:

          print("D")

      else:

          print("F")

  avg = sum/8

  print("Result Details of "+name)

  print("Average Score: "+str(avg))

  return avg

def determine_grade(result):

  if float(result) >= 90.0 and float(result) <= 100.0:

      print("Letter Grade: A")

  elif float(result) >= 80.0 and float(result) <90.0:

      print("Letter Grade: B")

  elif float(result) >= 70.0 and float(result) < 80.0:

      print("Letter Grade: C")

  elif float(result) >= 60.0 and float(result) < 70.0:

      print("Letter Grade: D")

  else:

      print("Letter Grade: F")

  print(" ")

for i in range(2):

  name = input("Student Name: ")

  result = calc_average(name)

  determine_grade(result)

See more about python at brainly.com/question/26104476

Ver imagen lhmarianateixeira
ACCESS MORE