Assigning multiple values from a single input statement disregarding whitespace
You are getting error because you're passing only one value as input. Instead, you should pass input like
1 2
input("msg").split()
split
by default takes space as separator
So your code is correct but you're providing wrong input
Accepting multiple values as input in Python
try this:
x = list(map(int, input('Enter 10 numbers ').split()))
print(x)
output:
Enter 10 numbers 1 2 34 56 100 22 340 344 44 5
[1, 2, 34, 56, 100, 22, 340, 344, 44, 5]
How can I input multiple values in one line?
You can do like this:
a, b, c, d, e = input("Insert the 5 values: ").split()
print(f"a: {a}\nb: {b}\nc: {c}\nd: {d}\ne: {e}")
Input:
1 2 3 4 5
Output:
a: 1
b: 2
c: 3
d: 4
e: 5
Asking for multiple Variables in one input Python
The following should do what you want:
A, B, C = (int(value) for value in input("how do I do this?").split(','))
print(A)
print(B)
print(C)
How do you insert multiple input at the same time in python?
You may try this way
a, b = [int(x) for x in input("Enter two values: ").split()]
print("First Number is: ", a)
print("Second Number is: ", b)
print()
How can I grab multiple values that a user inputs and put them in a list without having to continuously write input()?
By the code in your question, it accepts only ONE line of input. You need to write the whole block of code multiple times or you can utilize looping with while
in python.
For example, the process you can do step by step is:
- Set the looping and make it infinite unless it receives
quit
- Put the whole code block in the looping (
while True
) block. - Add the stopping condition, i.e. when it receives
quit 0
.
Here's the code for the steps above.
while True: # Make an infinite loop.
# Put the whole block to make sure it repeats
makeList = UserEntered.split()
get_item_1 = makeList[slice(0,1)][0]
get_item_2 = makeList[slice(1,2)][0]
# Print when the input is not `quit 0`
if "quit" not in makeList:
print("Eating {} {} a day keeps the doctor away.".format(get_item_2,get_item_1))
# Stopping control/condition here, when it receives `quit 0`
else:
break
Related Topics
How to Group a List of Tuples/Objects by Similar Index/Attribute in Python
Find First Sequence Item That Matches a Criterion
Removing a List of Characters in String
Correct Way to Implement a Custom Popup Tkinter Dialog Box
Type Hint for a Function That Returns Only a Specific Set of Values
Add Sum of Values of Two Lists into New List
Duplicate Log Output When Using Python Logging Module
Unnamed Python Objects Have the Same Id
Convert Row to Column Header for Pandas Dataframe,
Running Infinite Loops Using Threads in Python
How to Check If Code Is Executed in the Ipython Notebook
Prevent Pandas from Interpreting 'Na' as Nan in a String
How to Use a Multiprocessing.Manager()
It Is More Efficient to Use If-Return-Return or If-Else-Return