Complete-Python-3-Bootcamp icon indicating copy to clipboard operation
Complete-Python-3-Bootcamp copied to clipboard

need help with challenge SPY GAME: Write a function that takes in a list of integers and returns True if it contains 007 in order

Open LeeZee1 opened this issue 6 years ago • 0 comments

Hi, As part of the SPY GAME challenge question, I'm trying to write code that checks if the index for a '7' lies between two indexes with the same value '0' in the array nums. If it doesn't and if the index for a '7' falls after the index for the second '0', I want it to return True.

def spy_game(nums):
    first_0=nums.index(0)
    second_0=nums.index(0)
    seven=nums.index(7)
    for num in nums:
        if first_0<second_0 and first_0!=second_0 and nums[first_0:second_0+1]!=seven and seven>second_0:
            return True
        else:
            return False

I'm not sure what I'm doing wrong here as I get False for first check: spy_game([1,2,4,0,0,7,5])

Any help revising my code in the way I'm trying to complete the exercise would be great!

Thanks.

LeeZee1 avatar Mar 08 '20 19:03 LeeZee1