Home>

Please write your question in detail here.
Write a code in which the numbers "0", "1", and "2" are repeatedly output 2020 times in the order of 0 → 1 → 0 → 2 (→ 0 → 1 →…). I'm stumbling upon solving the example.

Cannot repeat processing with the specified number. Please professor.
Corresponding source code
Source code

sample_list = ["'0', '1', '0', '2'"]
for i in sample_list:
print (i)

What I tried

Since the challenge is to repeat the specified numbers 2020 times, I decided to list the specified numbers. After that, as far as I know, I tried to solve it by using range to repeat, but it will be repeated with a number other than the specified number.

Supplementary information (FW/tool version, etc.)

Please provide more detailed information here.

  • Answer # 1

    for i in range (2020):So, it will loop 2020 times, so you can write the numbers in the list in order.

    If you don't know that, you can run your code 505 times, 2020 ÷ 4 = 505.
    for j in range (2020 // 4):

  • Answer # 2

    Since only the answer using the for statement and range is given, I will write a program with a slightly different coat color.
    It may not be what you originally intended for the question, but keep in mind that there are some of these.

    >>>repeat = 4
    >>>print ('0 1 0 2'* 4)
    0 1 0 2 0 1 0 2 0 1 0 2 0 1 0 2


    Replace the first line of this program with repeat = 2020.

  • Answer # 3

    IN and OUT are not clear, but the expected code is

    sample_list = [0, 1, 0, 2]
    for _ in range (2020):
        print (* sample_list, end ='')
    print ()


    Or

    src = input ('3 digit number input>') # 012
    lst = src [0: 2] + src [0 :: 2] # 0102
    for _ in range (2020):
        print (* lst, end ='')
    print ()


    Does that mean?

  • Answer # 4

    I don't know what I want to do, but

    for i in range (2020):
      What (0)
      What (i + 1)


    I wonder if that mean