Advertisement
SansPapyrus683

6/5 Class Notes

Jun 5th, 2022
1,329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. def print_name(first_name, last_name):
  2.     # print(first_name)
  3.     print('hi ' + first_name + ' ' + last_name)
  4.  
  5.  
  6. def savings(pocket_money, paper_route, spending):
  7.     return pocket_money + paper_route - spending
  8.  
  9.  
  10. def scope_demo():
  11.     var1 = 10
  12.     var2 = 20
  13.     return var1 * var2
  14.  
  15.  
  16. main_script_var = 6
  17. def another_scope_demo():
  18.     var1 = 10
  19.     var2 = 20
  20.     return var1 * var2 - main_script_var
  21.  
  22.  
  23. def spaceship_building(cans, week_num):
  24.     total_cans = 0
  25.     for week in range(1, week_num + 1):
  26.         total_cans = total_cans + cans
  27.         print('week ' + str(week) + ': ' + str(total_cans))
  28.  
  29.  
  30. # prints out "hi kevin s" and "None" because of how returns work
  31. print(print_name('kevin', 's'))
  32. # just prints out 19
  33. print(savings(10, 15, 6))
  34. print(scope_demo())
  35. # print(var1)  # errors because var1 is only defined in the function
  36. print(another_scope_demo())
  37.  
  38. # adds 3 cans a week for 10 weeks (defined in parameters)
  39. spaceship_building(3, 11)
  40.  
  41. # quick module demo
  42. import time
  43.  
  44. print(time.asctime())
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement