Advertisement
JkSoftware

Day 12 - Global and Local scope

Nov 19th, 2021
1,183
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3.  
  4. enemies = 1
  5.  
  6. def increase_enemies():
  7.     enemies = 2
  8.     print(f"enemies inside function: {enemies}")
  9.  
  10. increase_enemies()
  11. print(f"enemies outside function: {enemies}")
  12.  
  13. #local scope
  14. # def drink_potion():
  15. #     potion_strength = 2
  16. #     print(potion_strength)
  17.  
  18. #drink_potion()
  19.  
  20.  
  21. #global scope
  22. player_health = 10
  23.  
  24. def drink_potion():
  25.     potion_strength = 2
  26.     print(potion_strength)
  27.     print(player_health)
  28.  
  29. drink_potion()
  30. print(player_health)
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement