Two values from one input in python?

前端 未结 18 2246
小鲜肉
小鲜肉 2020-11-28 03:46

This is somewhat of a simple question and I hate to ask it here, but I can\'t seem the find the answer anywhere else: is it possible to get multiple values from the user in

18条回答
  •  醉话见心
    2020-11-28 04:01

    This solution is being used for converting multiple string like ("22 44 112 2 34") to an integer list and you can access to the values in a list.

    n = input("") # Like : "22 343 455 54445 22332"
    
    if n[:-1] != " ":
    n += " "
    
    char = ""
    list = []
    
    for i in n :
        if i != " ":
            char += i
        elif i == " ":
            list.append(int(char))
            char = ""
    
    print(list) # Be happy :))))
    

提交回复
热议问题