I
I
igorloadgame2021-11-06 12:28:39
Python
igorloadgame, 2021-11-06 12:28:39

How to write down the variables in the number that were entered into the console?

There is a program that writes data to the console:

12 43
32 54
45 76

(That's right)
The number of pairs of variables depends on how many of them were entered into the console
n = int(input())
. And then the data pairs are entered.
How to write them into variables or into an array, or can it be somehow simpler?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dmshar, 2021-11-06
@igorloadgame

Have you read anything about the basics of Python? Loops, conditional statements, lists? And if you taught the basics of computer science (school, class probably 7 or 8), then you probably should know that the array was invented in order not to have a "separate variable" for each given one. Based on the confusion of the question, I strongly suspect not. How to translate into Russian the phrase " write down the variables in the amount that were entered into the console ?" - I don't know at all. What does "write variables in quantity" mean?, what is "which were entered into (!!!!) the console" ??? And "in the console" entered variables or all the same their number? ("In the console " (where?) You can "output", but you can enter "
Your program, the one that "writes to the console", how does it know how many pairs are entered? Where does she store her data?
What is n - each separately entered number or previously entered maximum amount of data?
If you work (and have read anything about) Python, you should know that it has a list data type that can grow dynamically and does not require you to predefine the maximum number of its elements. Here, as a new number appears, write it to the list, and if the length of the list is a multiple of two, print its last two elements to the console.

lst=[]
while True:
    lst.append(int(input()))
    if len(lst)%2==0:
        print(lst[-2],lst[-1])

Attention! The program contains an infinite loop. But I leave it to you to fix it as homework.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question