How do I gather user numerical input into a list in Python?

后端 未结 2 1245
隐瞒了意图╮
隐瞒了意图╮ 2020-12-12 08:15

I\'m new to Python and am trying to make a simple program to calculate mean median and mode from numbers input by user. So far I have:

num=[]
UserNumbers=int         


        
相关标签:
2条回答
  • 2020-12-12 08:44

    You have to parse the answer if you want it this way.

    UserNumbers=input("Enter number sequence separated by spaces: ")
    nums = [int(i) for i in UserNumbers.split()]
    

    EDIT:

    Duplicate of this question

    0 讨论(0)
  • 2020-12-12 08:58

    You can use this one line:

    user_numbers = [int(num) for num in raw_input
                    ("Enter number sequence separated by spaces: ").split()]
    

    Notes:

    • Read about PEP-8
    • Read about split
    • List comprehension
    0 讨论(0)
提交回复
热议问题