Get a list of numbers as input from the user

前端 未结 17 1154
生来不讨喜
生来不讨喜 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条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-11-21 23:17

    you can pass a string representation of the list to json:

    import json
    
    str_list = raw_input("Enter in a list: ")
    my_list = json.loads(str_list)
    

    user enters in the list as you would in python: [2, 34, 5.6, 90]

提交回复
热议问题