GAC-Machine

Corrected and original python code for drawing geometric figures

Aug 9th, 2025 (edited)
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | Source Code | 0 0
  1. # Original post https://www.facebook.com/photo/?fbid=608157219018212&set=a.216079138226024
  2. # Pastebin thread https://pastebin.com/x4yk4gp7
  3. print("Corrected Code that should be in the post:\n\n")
  4.  
  5. def print_diamond(rows):
  6.     for i in range(1, rows + 1):
  7.         print(" " * (rows - i) + "* " * (i))
  8.     for i in range (rows -1,0,-1):
  9.         print(" " * (rows - i) + "* " * (i))
  10.  
  11. print_diamond(5)
  12. print('\n')
  13.  
  14. def print_hollow_square(rows):
  15.     for i in range (rows+1):
  16.         if i == 0 or i == rows :
  17.             print("* " * rows)
  18.         else:
  19.             print("* " + "  " * (rows - 2) + "*")
  20.  
  21. print_hollow_square(5)
  22. print('\n')
  23.  
  24. def print_inverted_triangle(rows):
  25.     for i in range (rows, 0, -1):
  26.         print("* " * i)
  27.  
  28. print_inverted_triangle(5)
  29.  
  30. print("\n\n\nCode in the post:\n\n")
  31.  
  32. def print_diamond(rows):
  33.     for i in range(1, rows + 1):
  34.         print(" " * (rows - i) + "*" * (2*i-1))
  35.     for i in range (rows -1,0,-1):
  36.         print(" " * (rows - i) + "*" * (2*i-4))
  37.  
  38. print_diamond(5)
  39. print('\n')
  40.  
  41. def print_hollow_square(rows):
  42.     for i in range (rows+1):
  43.         if i == 0 or i == rows :
  44.             print("*" * rows)
  45.         else:
  46.             print("*" + " " * (rows - 2) + "*")
  47.  
  48. print_hollow_square(5)
  49. print('\n')
  50.  
  51. def print_inverted_triangle(rows):
  52.     for i in range (rows, 0, -1):
  53.         print("*" * i)
  54.  
  55. print_inverted_triangle(5)
Advertisement
Add Comment
Please, Sign In to add comment