Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. def replicate_iter(times, data):
  2. try:
  3. if type(data) is not(int) and type(data) is not(str):
  4. raise ValueError("Wrong Input Found!")
  5. arr = [];
  6. if times < 0:
  7. return arr
  8. for i in range(times):
  9. arr.append(data)
  10. return arr
  11. except(AttributeError,TypeError):
  12. raise ValueError("Wrong Input Found!")
  13.  
  14. def replicate_recur(times, data):
  15. try:
  16. if type(data) is not(int) and type(data) is not(str):
  17. raise ValueError("Wrong Input Found!")
  18. arr = []
  19. def recur(times, data):
  20. if times <= 0:
  21. return arr
  22. else:
  23. arr.append(data)
  24. return recur(times - 1, data)
  25. return recur(times, data)
  26. except(AttributeError,TypeError):
  27. raise ValueError("Wrong Input Found!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement