Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. # Create the list called "my_list" here, not within any function defined below.
  4. # That makes it a global object. We'll talk about that in another lab.
  5.  
  6. global my_list
  7. my_list = [100, 200, 300, 'six hundred']
  8.  
  9.  
  10. def give_list():
  11. # Does not accept any arguments
  12. # Returns all of items in the global object my_list unchanged
  13. return my_list
  14.  
  15. def give_first_item():
  16. # Does not accept any arguments
  17. # Returns the first item in the global object my_list as a string
  18. return my_list[0]
  19.  
  20. def give_first_and_last_item():
  21. # Does not accept any arguments
  22. # Returns a list that includes the first and last items in the global object my_list
  23. new_list = [my_list[0], my_list[-1]]
  24. return new_list
  25.  
  26. def give_second_and_third_item():
  27. # Does not accept any arguments
  28. # Returns a list that includes the second and third items in the global object my_list
  29. new_list = [my_list[1],my_list[2]]
  30. return new_list
  31.  
  32. if __name__ == '__main__': # This section also referred to as a "main block"
  33. print(give_list())
  34. print(give_first_item())
  35. print(give_first_and_last_item())
  36. print(give_second_and_third_item())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement