import random def main(): # main function definition aGrades=[] # empty list to store Grades for i in range(7): # loop to read 7 inputs print("Input scores ",i+1," : ", end="") # a message to enter grade n=int(input()) # input grade aGrades.append(n) # add grade into list print("Grade list before randomize: ",aGrades) # print list random.shuffle(aGrades) # randomize list numExams=len(aGrades)-1 # compute numExams FinalExam=aGrades[-1] # store final grade TotalPoints=sum(aGrades)-aGrades[-1] # compute TotalPoints TestAverage=TotalPoints/numExams # compute TestAverage FinalAverage=TestAverage*.6 + FinalExam*.4 # compute FinalAverage print("Grade list after randomize is: ",aGrades) # print list print("Test Average = %.2f"%TestAverage) # print test average print("Final Average = %.2f "%FinalAverage) # print final average main() # calling main function Can you explain in a word doc explaining each line of code and their variables.
Python code:
import random
def main(): # main function definition
aGrades=[] # empty list to store Grades
for i in range(7): # loop to read 7 inputs
print("Input scores ",i+1," : ", end="") # a message to enter grade
n=int(input()) # input grade
aGrades.append(n) # add grade into list
print("Grade list before randomize: ",aGrades) # print list
random.shuffle(aGrades) # randomize list
numExams=len(aGrades)-1 # compute numExams
FinalExam=aGrades[-1] # store final grade
TotalPoints=sum(aGrades)-aGrades[-1] # compute TotalPoints
TestAverage=TotalPoints/numExams # compute TestAverage
FinalAverage=TestAverage*.6 + FinalExam*.4 # compute FinalAverage
print("Grade list after randomize is: ",aGrades) # print list
print("Test Average = %.2f"%TestAverage) # print test average
print("Final Average = %.2f "%FinalAverage) # print final average
main() # calling main function
Can you explain in a word doc explaining each line of code and their variables. .
Step by step
Solved in 2 steps