In: Computer Science
the previous one I saw it, I wonder how to do the last one.
Read carefully
See the photo of the algorithm below after reading these
instructions: write a program in Python 3 which uses a list. Your
program will use a list to store the names and exam scores of
students. The program starts by asking how many results will be
entered. Then a loop will be used to enter the name and score for
each student. As each name and score is entered it is appended to a
list (which was initially empty). When the loop is finished (i.e.
all scores are entered) the program ends by printing the list.
Make a copy of your Lab6A.py file to Lab6B.py. Amend the comments accordingly for these instructions. Send the list you created in Lab 6A to a function which returns a list of names of all above average students.
Python Program:
def main():
""" Python Program that reads names and marks from
students and adds to list """
# Reading number of results
numResults = int(input("Specify how many results will
be entered? "))
# List that holds names and scores
names = []
scores = []
# Iterating and reading student data
for i in range(numResults):
# Reading names
name = input(" Enter student name:
")
score = int(input("Enter Score:
"))
# Adding to list
names.append(name)
scores.append(score)
# Printing list
print(names)
print(scores)
# Printing above average students
print(" Above average students: ")
print(aboveAvg(names, scores))
def aboveAvg(names, scores):
""" Function that returns names of above average
students """
# Finding average
avgScore = sum(scores)/len(scores)
# List that holds result names
resNames = []
# Iterating over each score
for i in range(0, len(scores)):
# Comparing score
if scores[i]>avgScore:
# Adding to
list
resNames.append(names[i])
# Returning result
return resNames
# Calling main function
main()
______________________________________________________________________________________________
Sample Run: