Ignoring the triangle part, the first step is to print all the numbers:
rows = int(input("Please Enter a Number : "))
for num in range(1, rows + 1):
print(num, end=" ")
From there we want to add an if to also print a new line if our number is
- equal to 'rows', or
- the number we expect to be at the end of the current level
Since the number of items in each row is an arithmetic progression (i.e. each level is +1 longer than the level above it) we can calculate the number at the end of each level using the formula for summing an arithmetic progression:
number_at_end_of_level = level * (level + 1) / 2
The simple explanation for this formula is that you're finding the average number of items in each level by averaging the first and last level average = (level + 1) / 2. Because we know the average, we can then multiply that by the number of levels to get the total.
So putting it all together the solution is:
rows = int(input("Please Enter a Number : "))
level = 1
for num in range(1, rows + 1):
print(num, end=" ")
number_at_end_of_level = level * (level + 1) / 2
if num == number_at_end_of_level or num == rows:
level += 1
print()
Alternatively, if you don't want to do the calculation, you can just count how many items you've printed in the current level and print a new line when that count is equal to the current level number:
rows = int(input("Please Enter a Number : "))
level = 1
current_level_count = 0
for num in range(1, rows + 1):
print(num, end=" ")
current_level_count += 1
if current_level_count == level or num == rows:
level += 1
current_level_count = 0
print()