The task is to check whether the last 3 digits from corresponding items from two lists are the same. If the items have a length of less than 3, it checks whether they are the same number.
If the two lists have different lengths it should return false, and if both lists have a length of 0, it should return true.
def corresponding_elements_have_same_end(list1, list2):
if len(list1) == len(list2):
for i in range(0, len(list1)):
num1 = str(list1[i])
num2 = str(list2[i])
if len(num1) <= 3 and len(num2) <= 3:
return num1 == num2
else:
return num1[-3:] == num2[-3:]
else:
return False
If I run it through this:
print("1.", corresponding_elements_have_same_end([3452, 43600, 10], [3111452, 600, 10]))
print("2.", corresponding_elements_have_same_end([452, 43600], [52, 600]))
print("3.", corresponding_elements_have_same_end([32, 43032], [32, 32]))
print("4.", corresponding_elements_have_same_end([32, 43132, 300], [32, 56132, 3300]))
It prints out
- True
- False
- True
- True
When it should print:
- True
- False
- False
- True