Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # given a list return the list in reverse order.
- def rev(input):
- # implement this function.
- pass
- # assertion checks
- assert rev([1,2,3,4]) == [4,3,2,1]
- assert rev([]) == []
- assert rev(["a"]) == ["a"]
- print("All tests passed. it works.")
- ##################################
- # given a number return true if it's a prime number otherwise return false.
- # assume that 1 is a prime number
- def is_prime(input):
- # implement this function.
- pass
- # assertion checks
- assert is_prime(1)
- assert is_prime(2)
- assert is_prime(3)
- assert not is_prime(4)
- assert is_prime(-17)
- assert is_prime(0)
- print("All tests passed. it works.")
- #################################
- # generate a list of 5 unique random numbers from 1 to 10.
- def lotto():
- # implement this function.
- return []
- # assertion checks
- for i in range(1,100):
- res = lotto()
- assert len(res) == 5
- for item in res:
- assert 1<=item<=10
- seen = []
- for item in res:
- assert item not in seen
- seen.append(item)
- print("All tests passed. it works.")
- #############################
- # given a list return true if the list is palindrome else return false
- # 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
- # [1,2,3,1] is not a palindrome.
- # [1,2,2,1] is a palindrome even though it has an even number of elements!
- def is_palindrome(input):
- # implement this function.
- pass
- # assertion checks
- assert is_palindrome([])
- assert is_palindrome([1])
- assert is_palindrome([1,3,1])
- assert is_palindrome([1,2,2,1])
- assert not is_palindrome([1,2,3])
- import random
- tmp = [-1]
- for i in range(1,10000):
- tmp.append(random.randint(1,10))
- assert not is_palindrome(tmp)
- print("All tests passed. it works.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement