Muna_Frank

Week4Code12

Feb 22nd, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. #Function that adds a number if greater than 5 and deletes the last number added
  2. def push_or_pop(data):
  3.      new_data = []
  4.      for num in data:
  5.         if num > 5:
  6.             new_data.append(num)
  7.         elif num <= 5:
  8.             new_data.pop()
  9.      return new_data
  10.      
  11. #Testing the function
  12. print(push_or_pop([10]))
  13. print(push_or_pop([10, 4]))
  14. print(push_or_pop([10, 20, 30]))
  15. print(push_or_pop([10, 20, 2, 30]))
Add Comment
Please, Sign In to add comment