0

How to take a definite number of inputs from a initial input in python?

Suppose first input is a number N, then how to take N more inputs? My question is how to set number of inputs from a given integer Input.

31st Jan 2021, 5:39 PM
Chandan Kumar Haboda
Chandan Kumar Haboda - avatar
5 Respuestas
+ 2
Assuming you're using Python: N = int(input()) for _ in range(N): next_input = input() # do something...
31st Jan 2021, 5:46 PM
Russ
Russ - avatar
+ 2
Russ thank you sir
31st Jan 2021, 6:36 PM
Chandan Kumar Haboda
Chandan Kumar Haboda - avatar
+ 1
times = int(input()) # mabey set up an empty container for time in times: whatever = input() # do something w/ input, mabey append to container
31st Jan 2021, 5:46 PM
Slick
Slick - avatar
+ 1
Lothar Russ Slick thank you everyone. I got it. But Now I am facing another problem. N = int(input()) For i in range(N): p,q = int(input()),int(input()) print( p + q ) I don't know why but I'm getting only one output that is the last input of p,q. But I want to get output for every p,q.Sorry I didn't know I'll face this this problem and now taking your precious time otherwise I'd have mentioned it in the question. Can anyone please help me out?
31st Jan 2021, 6:16 PM
Chandan Kumar Haboda
Chandan Kumar Haboda - avatar
+ 1
Indent your print statement so that you print the sum for every iteration, not just once after the for loop has finished.
31st Jan 2021, 6:34 PM
Russ
Russ - avatar