Jul-12-2017, 07:14 PM
As part of an assignment, I am supposed to make a number triangle that points to the left using only for loops and string format. I can kind of get it working using nested for loops, but I can't figure out how I can implement it with string formatting.
This is what I have so far, but it is a huge difference from the output that I am supposed to be getting.
This is what I have so far, but it is a huge difference from the output that I am supposed to be getting.
n = int(input("Level(1-15) ==> ")) for i in range(1, n): for j in range(n - i): print(" ", end = " ") for j in range(1, i): print(j, end = " ") print("\n")Expected output if the user enters 5:
Output: 1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
I would appreciate if someone could help me since my code is nowhere near that. Also, the numbers in the pyramid should be exactly the same, another problem that I cannot figure out how to solve. Any help would be appreciated.