Avatar ·

Determine the sequence of 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 on Python 3

📁 Advanced Python Topics, example, work

I try to solve the problem:

Write a program that displays part of the sequence 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 ... (the number is repeated as many times as its value). The input to the program is a positive integer N — the number of elements of the sequence that the program should output. The output is expected to be a sequence of numbers written separated by spaces on one line.

For example, if n = 7, then the program should output 1 2 2 3 3 3 4.

Sample input: 7

Sample output: 1 2 2 3 3 3 4