fork download
  1. def get_int(prompt):
  2. while True:
  3. try:
  4. value = int(input(prompt))
  5. if 1 <= value <= 8:
  6. return value
  7. except ValueError:
  8. pass # or perhaps continue
  9.  
  10. def pyramids(height):
  11. for row in range(height):
  12. spaces = height - row - 1
  13. hashes = row + 1
  14. # conditional spaces
  15. if spaces:
  16. print(" " * spaces, end="")
  17. print("#" * hashes, end="")
  18. print(" ", end="")
  19. print("#" * hashes) # no trailing spaces
  20.  
  21. def main():
  22. height = get_int("Height: ")
  23. pyramids(height)
  24.  
  25. #main()
  26. for ht in range(1, 9):
  27. print("-" * 8, str(ht), "-" * 8)
  28. pyramids(ht)
  29. # Prove a point
  30. assert (" " * 0) == " "
Success #stdin #stdout 0.05s 9552KB
stdin
Standard input is empty
stdout
-------- 1 --------
#  #
-------- 2 --------
 #  #
##  ##
-------- 3 --------
  #  #
 ##  ##
###  ###
-------- 4 --------
   #  #
  ##  ##
 ###  ###
####  ####
-------- 5 --------
    #  #
   ##  ##
  ###  ###
 ####  ####
#####  #####
-------- 6 --------
     #  #
    ##  ##
   ###  ###
  ####  ####
 #####  #####
######  ######
-------- 7 --------
      #  #
     ##  ##
    ###  ###
   ####  ####
  #####  #####
 ######  ######
#######  #######
-------- 8 --------
       #  #
      ##  ##
     ###  ###
    ####  ####
   #####  #####
  ######  ######
 #######  #######
########  ########