Create Python program code using a for loop. It will calculate and print the average GPA of 25 students in a class.
Could you help me create a python code for this question? Thanks
Consider a list for storing 25 students GPA
You can use in-built function or you can also write a simple code to find average.
Here, we will show how to write the code to find average without using in built function
gpaList=[]; #declare a list
print("Enter GPA's of 25 students "); #print message to enter inputs
for i in range(25): #for 25 times range() function will start from 0 and goes till 25 with step 1
gpaList.append(input()); #append the input value to list
sumOfGPAs=0; #variable to store sum of all GPA's
for element in gpaList: #for each and every element in list
sumOfGPAs=sumOfGPAs+float(element); #the input() will return string, so it is to be parsed to number and then added to sum
averageOfGPAs=sumOfGPAs/25; #calculate average by dividing sum by 25
print("The average GPAs of 25 students is: ",averageOfGPAs); #print averageOfGPAs
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images