'Average of a list in a python without pre-defined input [duplicate]

I have a question about the task below. I'm trying to find a way to convert the list I write into integers but seems I'm unable to find a way to do so. This is the first question.

list1 = input().split(',')  # removing the "," from the string of numbers
average = 0
sunOfNum = 0
for x in list1:  # each element of the list(string in my case) is being iterrated through 
    # and then it should go into sumOfNum but it's a string this is the issue I cannot get pass
    sunOfNum += x
    average = sunOfNum / len(list1)
print(average)

I believe if I can get the list into separated ints the solution of this task will be easy. But how to get it is the question. I read the TypeErr and understand it, tried with setting ints but it doesn't work as it's a list. Any help on this will be appreciated. I've also checked other solutions but they have a pre-defined list not one that you input into the console. Also I've checked the statistics.mean function but that is not how I'd like to solve it, with input I get other errors making things a bit more complicated.

The second question is would this condition actually matter and in which case? "Maintain the relative order of numbers."

Write a program that calculates the average of a list of numbers. Display the average, all the numbers below the average, and all the numbers above the average. Maintain the relative order of numbers.

Input

On the only line of input, you will receive the numbers, separated by a comma. Output

On the first line, print the average, with two digits after the decimal separator. On the second line, print all the numbers bellow the average On the third line, print all the numbers above the average.

Input

3,-12,0,0,13,5,1,0,-2

Output

avg: 0.89
below: -12,0,0,0,-2
above: 3,13,5,1


Solution 1:[1]

This is very simple in python you can just cast it to a int. Here's an example.

    list1 = input().split(',')  # removing the "," from the string of numbers
    average = 0
    sunOfNum = 0
    for x in list1:  # each element of the list(string in my case) is being iterrated through 
        # and then it should go into sumOfNum but it's a string this is the issue I cannot get pass
        sunOfNum += int(x)
        average = sunOfNum / len(list1)
    print(average)

For the other issue, I will need to see some code to help with that. You should consider creating a new thread.

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 thesonyman101