1

I tried my best to find it on different forums so excuse me if it is an easy one.

I want to take different inputs from the user and assign them to different variables. Using split() we can only enter the inputs in one line.

w,x,y,z = (input('Enter the number :').split(','))

But how can we ask for inputs in different line and assign them to the variables without typing the input function again.

I want the same output as below code but without typing input function multiple times.

w= int(input('Enter the number :'))
x= int(input('Enter the number :'))
y= int(input('Enter the number :'))
z= int(input('Enter the number :'))

1 Answer 1

2

One solution can be input 4 numbers to array and then assign them to variables. For example:

numbers = [int(input("Enter the number : ")) for _ in range(4)]
w, x, y, z = numbers

print(f"{w=} {x=} {y=} {z=}")

Prints:

Enter the number : 2
Enter the number : 3
Enter the number : 4
Enter the number : 5
w=2 x=3 y=4 z=5

Or:

w, x, y, z = [int(input("Enter the number : ")) for _ in range(4)]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.