Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. def triangle(size):
  2.     # triangle
  3.     #
  4.     # *
  5.     # * *  
  6.     # * * *  
  7.     # * * * *
  8.     # * * * * *
  9.  
  10.     row = 1
  11.     while row <= size:
  12.         print("* " * row)
  13.         row += 1
  14.  
  15. def rectangle(height, width):
  16.     # Rectangle
  17.     #
  18.     # * * * * * * *
  19.     # * * * * * * *
  20.     # * * * * * * *
  21.  
  22.     row = 1
  23.     while row <= height:
  24.         print("* " * width)
  25.         row += 1
  26.  
  27. def unfilled_rectangle(height, width):
  28.     # Unfilled rectangle
  29.     #
  30.     # 1 2 3 4 5 6 7
  31.     # * * * * * * *  1
  32.     # *           *  2
  33.     # *           *  3
  34.     # * * * * * * *  4
  35.  
  36.     row = 1
  37.     while row <= height:
  38.         if row == 1 or row == height:
  39.             print("* " * width)
  40.         else:
  41.             print("* " + ("  " * (width - 2)) + "* ")
  42.         row += 1
  43.  
  44.  
  45. print("Shape (triangle, [unfilled] square or [unfilled] rectangle)?")
  46. shape = input()
  47.  
  48. print("Height of the shape?")
  49. height = input()
  50. height = int(height)
  51.  
  52. if shape == "triangle":
  53.     triangle(height)
  54. elif shape == "rectangle":
  55.     print("Width of the rectangle?")
  56.     width = input()
  57.     width = int(width)
  58.    
  59.     rectangle(height, width)
  60. elif shape == "unfilled rectangle":
  61.     print("Width of the rectangle?")
  62.     width = input()
  63.     width = int(width)
  64.    
  65.     unfilled_rectangle(height, width)
  66. elif shape == "square":
  67.     rectangle(height, height)
  68. elif shape == "unfilled square":
  69.     unfilled_rectangle(height, height)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement