'Calculate average of random amount of numbers entered by user (python)

I need to make a code to calculate the average of numbers entered by user. What do I do to help it calculate the average. I tried using the sum function and Len but then it says something about int and str not being matched. I just need a hint. Basically, the code asks the user to enter the students name and then you enter it, and then it prompts you to enter their scores for topic 1, 2, 3. once you've done that, it asks if you have any more students left. If you say yes, it replays the code for you, if you say no, it stops the loop and calculates average first for topic 1, then topic 2, then topic 3. (I just need help, not the whole code)

while True: 
    name = str(input("Enter student name: ")) 
    print()
    Topic1 = int(input("Enter student score for topic 1: "))
    Topic2 = int(input("Enter student score for topic 2: "))
    Topic3 = int(input("Enter student score for topic 3: "))
    #calculate average of scores inputted by user for topic one, two, three.
    
    Continue = str(input("Would you like to add more students? "))
    if Continue == 'yes':
            continue
    elif Continue == 'no':
        break 


Solution 1:[1]

If I've understood your question correctly, you would want to append scores to separate lists for topic 1, 2, and 3 scores each time information for a new student is provided by the user. You can calculate the mean of a list of integers by dividing its sum by its length. I'm a little confused as to why you break at the end even if the user enters 'yes', but I'll leave that part up to you to work out.

topic1_scores = []
topic2_scores = []
topic3_scores = []

while True: 
    name = str(input("Enter student name: "))
    print()
    topic1_scores.append(int(input("Enter student score for topic 1: ")))
    topic2_scores.append(int(input("Enter student score for topic 2: ")))
    topic3_scores.append(int(input("Enter student score for topic 3: ")))

    topic1_average = sum(topic1_scores) / len(topic1_scores)
    topic2_average = sum(topic2_scores) / len(topic2_scores)
    topic3_average = sum(topic3_scores) / len(topic3_scores)
    #calculate average of scores inputted by user for topic one, two, three.
    
    Continue = str(input("Would you like to add more students? "))
    if Continue == 'yes':
            break   # why???
    elif Continue == 'no':
        break 

Solution 2:[2]

I don't know why you add break in if and elif it the same if it yes or no and also in if block the indentation is not correct.

if Continue == 'yes':
        break #in here
elif Continue == 'no':
    break 

I write some simple code for you can ask the number of subjects and ask for each amount and get the average of them to have a lock on it.

subjects = int(input('Enter number of subjects: '))
scores = []
for sub in range(0, subjects):
    sub_score = int(input(f'Enter subject {sub + 1} score: '))
    scores.append(sub_score)

avarage_score = sum(scores) / subjects
print(avarage_score)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ljdyer
Solution 2 Badrelden Ahmed