-1

Here's my code

#Gets a list of numbers from user
def get_score():
    score_list = []
    keep_going = 'y'
    while keep_going == 'y':
        score = float(input('Enter a test score: '))
        while score < 0:
            print('Positive numbers only')
            score = float(input('Enter a test score: '))
        score_list.append(score)
        keep_going = input("More scores (y/n) ")
    return score_list

#Finding the average based on user's input 
def calculated_average():
    numbers_of_grades = float(input)
    score_list = [int(s) for s in score_list]
    average = sum(score_list) / len(score_list)
    return average

def main():
    score = get_score()
    average = calculated_average(score)

main()

I'm trying to find the average grade based on the user's input, but it looks like there's something wrong at the calculating average part. I can't seem to figure out how to get the sum of the score_list. Any help is appreciated thanks!

petezurich
  • 9,280
  • 9
  • 43
  • 57
Xiao
  • 5
  • 4
  • 1
    Possible duplicate of [How can I force division to be floating point? Division keeps rounding down to 0?](https://stackoverflow.com/questions/1267869/how-can-i-force-division-to-be-floating-point-division-keeps-rounding-down-to-0) – SirGuy Oct 04 '18 at 15:18
  • 1
    "but it looks like there's something wrong at the calculating average part" - please make your problem statement clear. Give sample input and expected and actual result or error message you are getting. "something wrong" is not very clear – FlyingTeller Oct 04 '18 at 15:22
  • What do you think `numbers_of_grades = float(input)` does? – Matthias Oct 04 '18 at 15:22

2 Answers2

1

Fixed a couple of minor mistakes, basically you only forgot to parse the list of grades to your other function. It should work like this:

#Gets a list of numbers from user
def get_score():

    score_list = []
    keep_going = 'y'

    while keep_going == 'y':

        score = float(input('Enter a test score: '))

        while score < 0:

            print('Positive numbers only')
            score = float(input('Enter a test score: '))

        score_list.append(score)
        keep_going = input("More scores (y/n) ")

    return score_list

#Finding the average based on user's input
def calculated_average(score_list):

    numbers_of_grades = len(score_list)
    score_list = [int(s) for s in score_list]
    average = float(sum(score_list) / len(score_list))

    return average

def main():

    score = get_score()
    average = calculated_average(score)
    print(average)

main()
ttreis
  • 131
  • 7
1

You should just pass score to calculated_average and then you can simply return sum(x)/ len(x)

def calculated_average(x):
    return sum(x) / len(x)

def main():
    score = get_score()
    print(calculated_average(score))

main()
Enter a test score: 20
More scores (y/n) y
Enter a test score: 10
More scores (y/n) y
Enter a test score: 30
More scores (y/n) n
20.0
vash_the_stampede
  • 4,590
  • 1
  • 8
  • 20