Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Build a Pyramid of Blocks
- while True:
- num = int(input("Enter number of blocks (1, 3, 6, 10, 15 etc.): "))
- # Work out the number of rows required for the requested number of blocks
- rowmax, blks = 0, 0
- while blks < num:
- blks += rowmax
- rowmax += 1
- if blks == num:
- break
- print("Not a valid number of blocks\n")
- for row in range(rowmax -1):
- sp = (rowmax - row) * 2
- print(" " * sp + "[ ] " * (row+1))
- # Sample output:
- #
- # Enter number of blocks (1, 3, 6, 10, 15 etc.): 15
- # [ ]
- # [ ] [ ]
- # [ ] [ ] [ ]
- # [ ] [ ] [ ] [ ]
- # [ ] [ ] [ ] [ ] [ ]
- #
- # Process finished with exit code 0
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement