Avatar ·

output part of sequence 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 in Python 3

📁 Advanced Python Topics, example, work

I'm trying to solve this problem:

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

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

Sample Input: 7

Sample Output: 1 2 2 3 3 3 4

Here's what I have, the problem is that it doesn't work for large numbers.

a=int(input())b=''for i in