M
M
Mind20772022-01-05 19:02:54
Python
Mind2077, 2022-01-05 19:02:54

How to enter the number of variables to set?

I want to write a program. I will describe the essence of what cannot be implemented.
The user enters a number in input(). N Next, the user is given the opportunity through input to set the values ​​of N variables.
Example:
N = 2
then the user must enter the values ​​of the variables n1 and n2. How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JORIKUSS, 2022-01-05
@JORIKUSS

If I understand the task correctly, then you can add all the values ​​​​to the array and then work with numbers from the array using indexes.

N=int(input('Введите количество переменных: '))
n=[]
for i in range(N):
    n.append(int(input('Введите значение: ')))
print(n)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question