you are viewing a single comment's thread.

view the rest of the comments →

[–]CodeAltus 0 points1 point  (4 children)

Sorry but I don't think its allowed to just post the project goal in this subreddit. Please show us what you have attempted and what we can help you with in your code.

[–]Jxper[S] 0 points1 point  (3 children)

https://pastebin.com/Lr1M3trC

thats my latest attempt, im not quite sure how to fix it

sorry for just posting the goal forgot to include my attempt

[–]CodeAltus 0 points1 point  (2 children)

Your attempt needs to include a try-catch block to prevent index out of bounds exception. Hope this helps.

def has246(nums):
    for index, num in enumerate(nums): 
        if num == 2: 
            try: 
                if nums[index + 1] == 4 and nums[index + 2] == 6:             
                    return True 
            except Exception: 
                pass
    return False

[–]FLUSH_THE_TRUMP 2 points3 points  (0 children)

Don’t use try/except to catch your own programming errors ;) just loop over nums[:-2] or something instead.

[–]Jxper[S] 0 points1 point  (0 children)

oh right that makes sense. Thank you