Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # get user input
- user_input = -1 # initally set input to == a value of -1
- while user_input < 0 or user_input > 10: # run this while loop forever until the users input is > 0 or < 10
- user_input = int(input("Please enter pyramid height? ")) # get users input
- for i in range(1, user_input + 1): # nested outer forloop needed incrementing i up to the users input in order to build the spaces before the pyramid + pyramid itself
- print(" "*(user_input-i), end="") # print the spaces before the pyramid by using input-i everytime i increments
- print("#"*(i),end="") # build left alligned pyramid
- print(" ", end="") # build space between two pyramids
- print("#"*(i)) # build second right alligned pyramid
Advertisement
Add Comment
Please, Sign In to add comment