Get a list of numbers as input from the user

前端 未结 17 1358
生来不讨喜
生来不讨喜 2020-11-21 22:26

I tried to use raw_input() to get a list of numbers, however with the code

numbers = raw_input()
print len(numbers)

the input

17条回答
  •  萌比男神i
    2020-11-21 23:21

    It is much easier to parse a list of numbers separated by spaces rather than trying to parse Python syntax:

    Python 3:

    s = input()
    numbers = list(map(int, s.split()))
    

    Python 2:

    s = raw_input()
    numbers = map(int, s.split())
    

提交回复
热议问题