Python Question

Question 1
# Take two lists, say for example these two:
# a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
# b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
# and write a function that returns a list that contains only the elements that are common between the lists (without duplicates). Make sure your function works on two lists of different sizes.
# hint 1: You may want to use “if in”/”if not in” statements, for example:
x=[1,2,3,4]
if 4 in x:
print(“yes”)
if 5 not in x:
print(“no”)
# YOUR CODE
# hint 2: See if you can use set properties to solve this challenge without iteration. You can turn a set into a list easily by doing something like the following:
x=[1,2,3,4]
y=set(x)
print(type(y))
Question 2
# ATM machines allow 4 or 6 digit PIN codes and PIN codes cannot contain anything but exactly 4 digits or exactly 6 digits. Your task is to create a function that takes a string and returns True if the PIN is valid and False if it’s not.
# Hint: https://www.w3schools.com/python/ref_string_isdigi…
# YOUR CODE
# Examples
is_valid_PIN(“1234”) # True
is_valid_PIN(“12345”) # False
is_valid_PIN(“a234”) # False
is_valid_PIN(“”) # False
# Empty strings must return False.

 

Looking for a Similar Assignment? Let us take care of your classwork while you enjoy your free time! All papers are written from scratch and are 100% Original. Try us today! Use Code FREE15