0

Как за 1 ввод задать несколько переменных? How to create several variables in one input?

For example we firstly input 4. And then we must enter 4 variables on one line in one line. Например, мы сначала вводим 4. И затем мы должны ввести 4 переменных в одной строчке

11th Nov 2019, 8:07 AM
Марсель Халимов
9 Respostas
+ 1
You can take the input with spaces between them and then use the split method. name, birthplace = input().split() Depending on what it is, you might still transform a variable from str to what you need, for example int.
11th Nov 2019, 8:49 AM
HonFu
HonFu - avatar
0
Can you describe and write this code please
11th Nov 2019, 9:02 AM
Марсель Халимов
0
I gave you the pattern. Give it a try and apply it for what you need to do.
11th Nov 2019, 9:23 AM
HonFu
HonFu - avatar
0
I just do not quite understand what you wanted to say.
11th Nov 2019, 9:27 AM
Марсель Халимов
0
For example I enter firstly 5 and then I enter only 5 variables in a second line no more
11th Nov 2019, 9:29 AM
Марсель Халимов
0
You can take the number of inputs first. n=int(input()) And then you take one input, separated by spaces, and split it with the split method. If you want to insist on n number of inputs, you can after that use an if block: if n!=len(inputs): print('You were supposed to input', n, 'numbers!')
11th Nov 2019, 9:34 AM
HonFu
HonFu - avatar
0
думаю ввод -> переменная -> цикл будет достаточно просто )
12th Nov 2019, 10:10 PM
Vlad V
Vlad V - avatar
0
You can do like this: limit = int(input()) variables = [input() for _ in range(limit)] This will fill a list with your inputs
13th Nov 2019, 2:58 AM
Asman-H
Asman-H - avatar