The question is as follows: Given a list of ints, return True if the array contains a 3 next to a 3 somewhere.
has_33([1, 3, 3]) → True
has_33([1, 3, 1, 3]) → False
has_33([3, 1, 3]) → False
This is my answer:
def has_33(nums):
for i in nums:
if nums[i] == 3 and nums[i+1] == 3:
return True
else:
return False
When this code checked with:
has_33([1, 3, 3])
has_33([1, 3, 1, 3])
it properly worked.
But when it checked with: has_33([3, 1, 3])
What does 'list index out of range' means? and how to fix it?