Input Problem | SoloLearn: Learn to code for FREE!

+2

Input Problem

If we give simple code----> input() we provide a input and work on it But I want 4 inputs like this without writing it 4 times input("Enter number 1") input("Enter number 2") input("Enter number 3") input("Enter number 4") Plz help me with this stuff, I have tried many atttempts bt failed

10 Answers

New Answer

+8

for a in range(4): print(int(input('Enter number '+str(a+1))))

+5

For i in range(1,5): Input("enter number {0}". format(i))

+5

I would also recommend to convert the numbers from input to int or float. I have taken the 2 mentioned for loops and did it with a comprehension: inp = [] [inp.append(int(input(f'Enter {x + 1}. number: '))) for x in range(4)] print(inp)

+5

OK - here is a more simple code. It takes the 4 inputs and stores them in a list: inp = [] for x in range(4): inp.append(int(input(f'Enter {x + 1}. number: '))) print(inp)

+4

[Input() for i in range(4)]

+4

Thanks for respond Lothar but , it is little bit complicated I expect a simple one

+3

+1

Lothar will you help in this problem https://www.sololearn.com/Discuss/2277444/?ref=app

+1

for i in range(4): a=input("enter number"+str (i+1))

+1

Ashish Singh Jay Matthews have already answered same thing