I have the below homework problem for a python programming class, and i really need some help!!
First, take a set of 6 grades from a user and average them. Provide the average to the user. You need to check to make sure the grades are within the normal range. If the grade is less than 0 or more than 100, issue a warning to the user. You don't need to take the grade again, just let the user know.
Second, ask the user how many grades they have. Ask for all the grades and again provide an average. Make sure to check that the grades are within the normal range as above and issue a warning to the user.
For any function you use, use the following comment block as before the function to document it. # function: name # purpose: # inputs: # returns:
Code1:
def checkGrade(g):
if(g<0):
print("Grade must be greater than 0.")
return False
elif(g>100):
print("Grade must be less than 100.")
return False
else:
return True
def avg(grades):
s = 0
for i in range(len(grades)):
s+=grades[i]
return s/len(grades)
grades = []
i = 0
while(True):
if(i<5):
print("Enter your grade ",i+1)
g = int(input())
if (checkGrade(g)):
grades.append(g)
i+=1
else:
break
print("Entered grades are: ")
print(grades)
print("Average of all grades is : %d\n"%avg(grades))
Output:
Code2:
def checkGrade(g):
if(g<0):
print("Grade must be greater than 0.")
return False
elif(g>100):
print("Grade must be less than 100.")
return False
else:
return True
def avg(grades):
s = 0
for i in range(len(grades)):
s+=grades[i]
return s/len(grades)
grades = []
i = 0
n = int(input("Enter the number of grades you want to
enter:"))
while(True):
if(i<n):
print("Enter your grade ",i+1)
g = int(input())
if (checkGrade(g)):
grades.append(g)
i+=1
else:
break
print("Entered grades are: ")
print(grades)
print("Average of all grades is : %d\n"%avg(grades))
Output:
Get Answers For Free
Most questions answered within 1 hours.