In your example you probably typed just one number on the line, and the error was raised because you expect 2 (a and b)
You should type both numbers on the same line, then enter.
You can change your code to accept any number of numbers, and store them in a list:
res = input("Enter your numbers:").split()
print(*res) ## prints the list content
for r in res: ## prints number one by one and one per line
print(r)
result:
Enter your numbers: 12 13 14
12 13 14
12
13
14
Answer from Malo on Stack OverflowGeeksforGeeks
geeksforgeeks.org โบ python โบ taking-multiple-inputs-from-user-in-python
Taking multiple inputs from user in Python - GeeksforGeeks
June 26, 2026 - One of the simplest ways to take multiple inputs from a user in Python is by using the input() function along with the split() method.
How to take more inputs from a user at the same time in Python?
The split() method will generate a list. number_list = input("Please input multiple integers separated by commas: ").split(',') Note that this will generate a list of strings. If you want to convert them to integers for later use, you'll need another step. More on reddit.com
Using split(): method in Python 3 to get multiple inputs - Stack Overflow
I am working on a project where I need to implement code that will ask the user for multiple data inputs for the following fields for an employee directory: Last name, first name, employee number, ... More on stackoverflow.com
Taking multiple integers on the same line as input from the user in python - Stack Overflow
In Python 2, you can input multiple values comma separately (as jcfollower mention in his solution). But if you want to do it explicitly, you can proceed in following way. I am taking multiple inputs from users using a for loop and keeping them in items list by splitting with ','. More on stackoverflow.com
How to take either multiple or single input on one line from Python - Stack Overflow
To accept multiple inputs on one line, I know you can do something like: a, b = input().split() And if the user were to only type 1 input, they would come across a ValueError: "ValueError: not More on stackoverflow.com
What is the role of split() in taking multiple inputs in Python?
split() divides a string into individual elements based on a delimiter, usually a space. It allows you to take multiple inputs in Python in one line and store them in a list for further processing.
upgrad.com
upgrad.com โบ home โบ blog โบ data science โบ how to take multiple inputs in python: techniques and best practices
Multiple Input in Python: Techniques, Loops & Best Practices
How do you take multiple inputs from a file in Python?
Use the open() function or the fileinput module to read lines from a file. You can then process each line and convert values to integers, floats, or strings. This is a practical way to handle multiple inputs in Python from external files.
upgrad.com
upgrad.com โบ home โบ blog โบ data science โบ how to take multiple inputs in python: techniques and best practices
Multiple Input in Python: Techniques, Loops & Best Practices
How do you unpack multiple inputs into separate variables in Python?
If the number of inputs is fixed, you can unpack them directly: a, b, c = map(int, input().split()). Each input is assigned to a variable, making it easy to work with multiple inputs in Python without manually indexing a list.
upgrad.com
upgrad.com โบ home โบ blog โบ data science โบ how to take multiple inputs in python: techniques and best practices
Multiple Input in Python: Techniques, Loops & Best Practices
08:04
๐ Python Tutorial #27: Splitting and Joining Strings - YouTube
Input a List using split() Method and Loops in Python
08:27
Input a List using split() Method in Python - YouTube
06:23
Two or More Input in Single Line in Python split() and map() | ...
05:55
Python Tutorial | Multiple input in single line python code, use ...
09:49
Multiple inputs in one line in python, Split function in Python, ...
DEV Community
dev.to โบ mohit355 โบ 3-5-split-method-in-python-2e19
3.5 split() method in Python - DEV Community
December 19, 2019 - grocery = 'Milk, Chicken, Bread, Butter' print(grocery.split(', ', 2)) print(grocery.split(', ', 1)) print(grocery.split(', ', 0)) print(grocery.split(', ', 5)) ['Milk', 'Chicken', 'Bread, Butter'] ['Milk', 'Chicken, Bread, Butter'] ['Milk, Chicken, Bread, Butter'] ['Milk', 'Chicken', 'Bread', 'Butter'] Developer often wants a user to enter multiple values or inputs in one line. In C++/C user can take multiple inputs in one line using scanf but in Python user can take multiple values or inputs in one line by two methods.
IncludeHelp
includehelp.com โบ python โบ taking-multiple-inputs-from-the-user-using-split-method.aspx
Taking multiple inputs from user in Python
To take multiple inputs from the user in Python, you can simply use the combination of input() and split() method like input().split() and write the multiple values as input with separators/delimiters.
Reddit
reddit.com โบ r/learnpython โบ how to take more inputs from a user at the same time in python?
r/learnpython on Reddit: How to take more inputs from a user at the same time in Python?
February 16, 2023 -
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.
Top answer 1 of 4
3
The split() method will generate a list. number_list = input("Please input multiple integers separated by commas: ").split(',') Note that this will generate a list of strings. If you want to convert them to integers for later use, you'll need another step.
2 of 4
3
Other than the split method with specified separator others have mentioned you can also use regex here to be a bit more versatile. import re pattern = r'\d+' # one or more digits raw_input = input("prompt") # you get 1, 2, 3 or 1 2 3 or 1,2,3 or 1|2|3 numbers = re.findall(pattern, raw_input) # ['1', '2', '3'] after that you can just cast them to integers ([int(n) for n in numbers] or map(int, numbers)) If I go that route my code would probably be something like def get_numbers(prompt: str) -> list[int]: return [int(x) for x in re.findall(r'\d+',input(prompt))] integers = get_numbers("Enter a list of integers: ")
Scaler
scaler.com โบ home โบ topics โบ how to take multiple input in python?
How to Take Multiple Input in Python? - Scaler Topics
March 30, 2024 - To give multiple input in Python, the split() function in Python helps to split the multiple input fed by the user into single individual values for each variable. The method takes two parameters as part of its syntax that is, the separator and the maxsplit. When we input values in a single ...
TutorialsPoint
tutorialspoint.com โบ taking-multiple-inputs-from-user-in-python
Taking multiple inputs from user in Python
July 11, 2020 - # taking the input from the user numbers = input("Enter multiple numbers space-separated:- ") # splitting the data and converting each string number to int numbers = list(map(int, numbers.split())) # printing the data print(numbers)
Recenturesoft
recenturesoft.com โบ taking-multiple-inputs-from-user-in-python
How to take Multiple Inputs in Python? 100% working tips | Recenturesoft
In this example, we will take two inputs from the user and then print them. num = list(map(int, input("Enter a multiple value: ").split())) print("List of students: ", num) We can use this method to take multiple inputs in Python from the user. This is generally used when we want input for a list.
StudySmarter
studysmarter.co.uk โบ python multi input
Python Multi Input: Techniques & Examples | StudySmarter
One of the simplest and most effective ways to capture multiple inputs is by using the input() function combined with split(). This method splits a single input string into separate components, which can be processed individually or collectively. Imagine asking users to enter their names, ages, ...
Stack Overflow
stackoverflow.com โบ questions โบ 28665527 โบ using-split-method-in-python-3-to-get-multiple-inputs
Using split(): method in Python 3 to get multiple inputs - Stack Overflow
February 23, 2015 - I am working on a project where I need to implement code that will ask the user for multiple data inputs for the following fields for an employee directory: Last name, first name, employee number, and pay rate. ... user_input = input("enter last name, first name, employee number, and pay rate: ") a = user_input.split() print (a[0]) # last name print (a[1]) # first name print (a[2]) # employee number print (a[3]) # pay rate
Top answer 1 of 16
17
This might prove useful:
Use with AIa,b=map(int,raw_input().split())
You can then use 'a' and 'b' separately.
2 of 16
16
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)
Stack Overflow
stackoverflow.com โบ questions โบ 73601515 โบ how-to-take-either-multiple-or-single-input-on-one-line-from-python
How to take either multiple or single input on one line from Python - Stack Overflow
a, *b = input().split() print(f'first variable is {a}') print(f'there is {"a" if b else "no"} second variable') if b: print(f'second variable is {b[0]}')
CodeChef
codechef.com โบ learn โบ course โบ python โบ LTCPY10 โบ problems โบ PYTHCL50C
Multiple string inputs in Python Programming
Test your Learn Python Programming knowledge with our Multiple string inputs practice problem. Dive into the world of python challenges at CodeChef.
GeeksforGeeks
geeksforgeeks.org โบ python โบ input-and-output-in-python
Input and Output in Python - GeeksforGeeks
Python ยท s = "Brad" print(s) s ... splitting the values entered by the user into separate variables for each value using the split() method: Python ยท...
Published: September 19, 2026