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
For n
number of inputs declare the variable as an empty list and use the same syntax to proceed:
>>> x=input('Enter value of a and b').split(",")
Enter value of a and b
1,2,3,4
>>> x
['1', '2', '3', '4']
I tried this in Python 3 , seems to work fine .
a, b = map(int,input().split())
print(a)
print(b)
Input : 3 44
Output :
3
44
Check this handy function:
def gets(*types):
return tuple([types[i](val) for i, val in enumerate(raw_input().split(' '))])
# usage:
a, b, c = gets(int, float, str)
All input will be through a string. It's up to you to process that string after you've received it. Unless that is, you use the eval(input()) method, but that isn't recommended for most situations anyway.
input_string = raw_input("Enter 2 numbers here: ")
a, b = split_string_into_numbers(input_string)
do_stuff(a, b)
if we want to two inputs in a single line so, the code is are as follows enter code here
x,y=input().split(" ")
print(x,y)
after giving value as input we have to give spaces between them because of split(" ") function or method.
but these values are of string type if to perform some arithmetic operations we have to convert the type of x,y are as follows int(x),int(y)
we can do this also with the help of list in python.enter code here
list1=list(map(int,input().split()))
print(list1)
this list gives the elements in int type
Two inputs separated by space:
x,y=input().split()