'none' output for list


#1



https://www.codecademy.com/en/courses/python-intermediate-en-7mgOa/2/3?curriculum_id=4f89dab3d788890003000096


So I ported the exercise into PyCharm to see if I could do it on my own. I'm satisfied with the result expect that in the output I'm always getting an annoying 'none' after the list of scores in my list, like so:

Enter the scores separated by a space, please:123 3 4
Your list of scores you put it is:
123
3
4
None
The average is:
43.33
The variance is:
4760.33
The standard deviation is:
69.0

My question is; why is that none there and how do I get rid of it? that would make my output a lot more legible. Thank you in advance.


s = input("Enter the scores separated by a space, please:")
numbers = list(map(int, s.split()))

def print_list(num):
    for n in num:
        print (n)
print ("Your list of scores you put in is:")
print (print_list(numbers))

def sum_numbers(num):
    sum = 0.0
    for n in num:
        sum += n
    return sum

def average_numbers(num):
    sum = sum_numbers(numbers)
    average = round(sum / len(numbers), 2)
    return average
print ('The average is:')
print (average_numbers(numbers))

def variance_numbers(num):
    average = average_numbers(num)
    sum_score = 0.0
    for n in num:
        sum_score += (n - average) ** 2
    variance = round(sum_score / (len(num)-1), 2)
    return variance
print ('The variance is:')
print (variance_numbers(numbers))

def std_numbers(num):
    variance = variance_numbers(num)
    std = round(variance ** 0.5, 2)
    return std
print ('The standard deviation is:')
print (std_numbers(numbers))


#2

here:

print (print_list(numbers))

you use print on the function call, but print_list doesn't return anything? So the default (None) is returned

simply get rid of the print at the function call, so what the function returns isn't printed


#3

Oh, yes, that makes sense. Thank you so much! :slight_smile:


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.