import random; #importing random module aGrades=[]; #list to store grades of all tests for i in range(0,7): aGrades.append(random.randrange(0,100)); #generating 7 random values for tests examCount=len(aGrades)-1; #examCount is a variable to store count of all exams except last exam totalPoints=sum(aGrades)-aGrades[len(aGrades)-1]; #totalPoints is a variable to store sum of all scores excluding last exam testAverage=(totalPoints)/examCount; #testAverage is a variable used to store the average of scores except last exam finalAverage= (testAverage*0.6)+(aGrades[len(aGrades)-1]*0.4); #finalAverage is a variable to store weighted average of the tests print(aGrades); #printing list of grades print(testAverage); #printing test average print(finalAverage); #printing final average How do i rewrite the Grades List programs above using a loop instead of referencing the elements of the lists by index.
import random; #importing random module
aGrades=[]; #list to store grades of all tests
for i in range(0,7):
aGrades.append(random.randrange(0,100)); #generating 7 random values for tests
examCount=len(aGrades)-1; #examCount is a variable to store count of all exams except last exam
totalPoints=sum(aGrades)-aGrades[len(aGrades)-1]; #totalPoints is a variable to store sum of all scores excluding last exam
testAverage=(totalPoints)/examCount; #testAverage is a variable used to store the average of scores except last exam
finalAverage= (testAverage*0.6)+(aGrades[len(aGrades)-1]*0.4); #finalAverage is a variable to store weighted average of the tests
print(aGrades); #printing list of grades
print(testAverage); #printing test average
print(finalAverage); #printing final average
How do i rewrite the Grades List
Step by step
Solved in 4 steps with 3 images