0
variable amount of inputs in python?
Dear community, is there a way to choose how many inputs will be processed through the code while running it? For example: I want to be able to address 1 OR 2 items from a list through inputs, without changing the code and delete or add one input. I know you could assign sth like "x" for inputs (if input()==x: ...), sothat they will be treated differently, but is there an other way?
1 Resposta
+ 1
Assuming I understood you correctly...
Ask the user how many inputs they are going provide. Then use a loop to take that number of inputs. Something along the lines of
n = int(input()) # number of inputs
data = [] # list storing the inputs
for i in range(n):
data.append(input())