Advertisement
Guest User

new

a guest
Mar 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. #Chap.3 Functions Hw
  2. print('#3.1')
  3. #3.1
  4. def right_justify(s):
  5.     a = len(s)
  6.     b = ' '
  7.     c = 70 - a
  8.     d = b*c+s
  9.    
  10.     print(len(d))
  11.     print(d)
  12.    
  13. right_justify('monty')
  14.  
  15.  
  16. print('\n')
  17. print('#3.2.1')
  18. #3.2.1
  19. def do_twice(f):
  20.     f()
  21.     f()
  22. def print_spam():
  23.     print('spam')
  24.    
  25. do_twice(print_spam)
  26.  
  27.  
  28. print('\n')
  29. print('#3.2.2-5')
  30. #3.2.2-5
  31. def do_twice(f,s):
  32.     f(s)
  33.     f(s)
  34. def print_twice(s):
  35.     print(s)
  36.     print(s)
  37. def do_four(f,s):
  38.     do_twice(f,s)
  39.     do_twice(f,s)  
  40.  
  41. do_twice(print_twice, 'spam1')
  42. do_four(print_twice, 'spam2')
  43.  
  44.  
  45. print('\n')
  46. print('#3.3')
  47. #3.3
  48. def do_twice(f):
  49.     f()
  50.     f()
  51. def do_four(f):
  52.     do_twice(f)
  53.     do_twice(f)
  54. def print_beam():
  55.     print('+ - - - -', end = ' ')
  56. def print_post():
  57.     print('|        ', end = ' ')
  58. def print_beams():
  59.     do_twice(print_beam)
  60.     print('+')
  61. def print_posts():
  62.     do_twice(print_post)
  63.     print('|')
  64. def print_row():
  65.     print_beams()
  66.     do_four(print_posts)
  67. def print_grid():
  68.     do_twice(print_row)
  69.     print_beams()
  70.    
  71. print_grid()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement