try this:
a , b , c = map(int,(input().split()))
Answer from Mahdi F. on Stack Overflowtry this:
a , b , c = map(int,(input().split()))
You can do like this:
a, b, c = input("Insert the 3 values: ").split()
print(f"a: {a}\nb: {b}\nc: {c}")
See this similar question for more details
Taking 3 inputs in the same line in Python 3.5 - Stack Overflow
How to take more inputs from a user at the same time in Python?
How to take multiples inputs in a single line in python 3? - Stack Overflow
How to take n numbers as input in single line in Python - Stack Overflow
How can you take multiple string inputs in Python?
How do you convert multiple inputs in Python to integers or floats?
How do you take multiple inputs from a file in Python?
This might prove useful:
Use with AIa,b=map(int,raw_input().split())
You can then use 'a' and 'b' separately.
How about something like this?
Use with AIuser_input = raw_input("Enter three numbers separated by commas: ")
input_list = user_input.split(',')
numbers = [float(x.strip()) for x in input_list]
(You would probably want some error handling too)
Please try
n,a,k = map(int, input().split())
int can receive one string only.
Since others have given a map solution, here is one using a simple list comprehension:
n,a,k = [int(i) for i in input().split()]
Does it have an advantage over map()? Not really, but some prefer this approach.
Hi!
How I can take more inputs (integers) from a user at the same time? I know that I need to use a list and .split(), but I dont know how.
You could use.
separator = ' '
parameters = input("parameters:").split(separator)
e.g.
Python 3.6.5 (default, Mar 30 2018, 06:42:10)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> separator = '-'
>>> parameters = input("parameters:").split(separator)
parameters:5-6
>>> parameters
['5', '6']
>>>
you can use the map function that will append the inputs to a list if , suppose you have to take any n no of inputs
arr = list(map(int,input().split()))
all the elements entered will be stored as integer in arr list.
The following snippet will map the single line input separated by white space into list of integers
lst = list(map(int, input().split()))
print(lst)
Output:
$ python test.py
1 2 3 4 5
[1, 2, 3, 4, 5]
This will convert numbers separated by spaces to be stored in ar:
ar = list(map(int, input().strip().split(' ')))
Strip() is used to remove all the leading and trailing spaces from a string, so that it is clear and easy to classify/distinguish inputs.
Use a combination of split and sequence unpacking.
user_input = user_input(" Please enter the numbers: ")
a, b, c = user_input.split()
split will take your string of numbers, say "x y z", and turn it into a list of elements in the string where the elements are all the words in the string that are separated by spaces. Thus split will yield the string ['x', 'y', 'z'] for input 'x y z'.
Since a list is a form of sequence, its elements can be "unpacked" and assigned to a list of variables of your choosing.
x = (input("Enter 3 user inputs: ").split())
a = int(x[0])
b = int(x[1])
c = int(x[2])
print(f"A: {a}, B: {b}, C: {c}")
You messed up with parenthesis (split works on string not int) then you expect a tuple for x,y = ...
the solution is:
x, y = [int(i) for i in input("->").split()]
print(x, y)
You are taking int as input which cant be split
x,y = input("->").split()
print(x,y)
you can change to int if you like later
print(int(x),int(y))