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.71 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.        
  10.         print(anylist[:2])
  11.        
  12. split_in_two(["fish", "dogs", "chemistry", "pentane", "magic", "absolute value"]
  13. , 2)
  14. split_in_two(["fish", "dogs", "chemistry", "pentane", "magic", "absolute value"]
  15. , 1)
  16. split_in_two(["fish", "dogs", "chemistry", "pentane", "magic", "absolute value"]
  17. , 15)
  18. split_in_two(["fish", "dogs", "chemistry", "pentane", "magic", "absolute value"]
  19. , 6)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement