In: Computer Science
USING PYTHON ONLY
Write a gradebook program that lets a teacher keep track of test averages for his or her students. Your program should begin by asking the teacher for a number of students in their class as well as the total # of tests that will be given to the class. Validate this information to ensure that the numbers entered are positive.
Next, prompt the teacher to enter in scores for each student. Ensure that the values entered are positive - if they aren't you will need to re-prompt them. Hint: you may need to use nested loops here! A "while" loop can be placed inside of a "for" loop, if necessary.
Once your program has collected all test scores for a student it should display that student's average and move onto the next student. When all students have been calculated the program should compute the overall average score for the entire class.
Here's a sample running of your program:
How many students are in your class? -5 Invalid # of students, try again. How many students are in your class? 3 How many tests in this class? -10 Invalid # of tests, try again. How many tests in this class? 2 Here we go! **** Student #1**** Enter score for test #1: -50 Invalid score, try again Enter score for test #1: 50 Enter score for test #2: 75 Average score for student #1 is 62.50 **** Student #2**** Enter score for test #1: 100 Enter score for test #2: 90 Average score for student #2 is 95.00 **** Student #3**** Enter score for test #1: -10 Invalid score, try again Enter score for test #1: -20 Invalid score, try again Enter score for test #1: -30 Invalid score, try again Enter score for test #1: 90 Enter score for test #2: 80 Average score for student #3 is 85.00 Average score for all students is: 80.83
Some hints:
Python program code along with URL link of program and output screen as similar expected result are given below:
You can see the python code below or You may copy and paste the given URL link in your web browser .
URL link of program: https://repl.it/repls/TenseOrnateScan#main.py
Python code:
# Taking input from user for number of students
n = int(input("Enter the number of students in a class: "))
# Creating list for storing average values
li1 = []
# Condition for invalid entry
if(n<0):
while(n<0):
n1 = int(input("Invalid # of students, try again.\n\nHow many students are in your class? "))
n = n1
t = int(input("How many tests in this class? "))
# Condition for invalid entry
if(t<0):
while(t<0):
t1 = int(input("Invalid # of tests, try again.\nHow many tests in this class? "))
t = t1
print("\nHere we go!\n")
for i in range(1,n+1):
li = []
x = 0.0
print("****Student #",i,"****")
for j in range(1,t+1):
print("Enter the score of test #",j)
z = int(input())
# Condition for invalid entry
if(z<0):
while(z<0):
z1 = int(input("Invalid score, try again for same test "))
z = z1
li.append(z)
# Applying formula for average
x = sum(li)/len(li)
# Finding average of students
print("Average score for student #",i," is ",x)
print("\n")
li1.append(x)
y = 0.0
# Applying formula for average
y = sum(li1)/len(li1)
# Giving output as average of all students
print("Average score for all students is: ",y)
Output screen:
Thank you!!! Good luck! keep coding :)