Guest User

Untitled

a guest
Aug 26th, 2019
86
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # given a list return the list in reverse order.
  2.  
  3. def rev(input):
  4. # implement this function.
  5. pass
  6.  
  7. # assertion checks
  8. assert rev([1,2,3,4]) == [4,3,2,1]
  9. assert rev([]) == []
  10. assert rev(["a"]) == ["a"]
  11.  
  12. print("All tests passed. it works.")
  13.  
  14.  
  15. ##################################
  16.  
  17. # given a number return true if it's a prime number otherwise return false.
  18. # assume that 1 is a prime number
  19.  
  20. def is_prime(input):
  21. # implement this function.
  22. pass
  23.  
  24. # assertion checks
  25. assert is_prime(1)
  26. assert is_prime(2)
  27. assert is_prime(3)
  28. assert not is_prime(4)
  29. assert is_prime(-17)
  30. assert is_prime(0)
  31.  
  32.  
  33. print("All tests passed. it works.")
  34.  
  35.  
  36. #################################
  37.  
  38. # generate a list of 5 unique random numbers from 1 to 10.
  39.  
  40. def lotto():
  41. # implement this function.
  42. return []
  43.  
  44. # assertion checks
  45.  
  46. for i in range(1,100):
  47. res = lotto()
  48. assert len(res) == 5
  49. for item in res:
  50. assert 1<=item<=10
  51. seen = []
  52. for item in res:
  53. assert item not in seen
  54. seen.append(item)
  55.  
  56.  
  57.  
  58.  
  59. print("All tests passed. it works.")
  60.  
  61. #############################
  62.  
  63.  
  64. # given a list return true if the list is palindrome else return false
  65. # palindrome: a list that is the same if read from left or right. E.g [1,2,1] and [1,4,4,5,4,4,1] are palindromes
  66. # [1,2,3,1] is not a palindrome.
  67. # [1,2,2,1] is a palindrome even though it has an even number of elements!
  68.  
  69. def is_palindrome(input):
  70. # implement this function.
  71. pass
  72.  
  73. # assertion checks
  74. assert is_palindrome([])
  75. assert is_palindrome([1])
  76. assert is_palindrome([1,3,1])
  77. assert is_palindrome([1,2,2,1])
  78. assert not is_palindrome([1,2,3])
  79.  
  80. import random
  81. tmp = [-1]
  82. for i in range(1,10000):
  83. tmp.append(random.randint(1,10))
  84. assert not is_palindrome(tmp)
  85.  
  86.  
  87. print("All tests passed. it works.")
RAW Paste Data