Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. # This is a split_in_two function that accepts a list and a numrber.
  2. # if number is even, it returns the list elements from the third  element to the end.
  3. # if the number is odd, it returns the list elements from index 0 to 2
  4.  
  5. def split_in_two(anylist, number):
  6.     if number % 2 == 0:
  7.         print(anylist[3:])
  8.     else:
  9.         print(anylist[:2])
  10.        
  11. split_in_two(["fish", "dogs", "chemistry", "pentane", "magic", "absolute value"]
  12. , 2)
  13. split_in_two(["fish", "dogs", "chemistry", "pentane", "magic", "absolute value"]
  14. , 1)
  15. split_in_two(["fish", "dogs", "chemistry", "pentane", "magic", "absolute value"]
  16. , 15)
  17. split_in_two(["fish", "dogs", "chemistry", "pentane", "magic", "absolute value"]
  18. , 6)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement