Accepting Multiple User Inputs Separated By A Space In Python And Append Them To A List
How can I accept multiple user inputs separated by a space? I don't know the number of inputs, but I do know they are all ints. Here's some example inputs: 13213 412 8143 12 312 13
Solution 1:
s = raw_input("Please enter your numbers: ")
mynums = [int(i) for i in s.split()]
# ORmynums = map(int, s.split())
Solution 2:
Try this:
nums = [int(i) for i inraw_input("Enter space separated inputs: ").split()]
Solution 3:
for python 2.x
x,y = map(int,raw_input().split())
it take two variable x and y of int type separated by space and you can replace int with your desired type
for python 3.x
x,y = input().split()
it takes two variables x and y of string type separated by space and you have to convert explicitly
Solution 4:
x,y=map(int,input().split())
#this will take input separated by space and map #into int
Post a Comment for "Accepting Multiple User Inputs Separated By A Space In Python And Append Them To A List"