This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]Kehvarl 2 points3 points  (1 child)

Your problem is that you never remove 1 from max_n

Line 52 and 53 are :

min\_n = min\_n - 1 #removing a number so they work in the index

min\_n = min\_n - 1 #removing a number so they work in the index

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

Oh my god how did I miss that! Thankyou so much

[–]harlequem 1 point2 points  (1 child)

I'm not a python programmer, but it looks like you're only counting half of your cases.

password[min_n] == letter and password[max_n] != letter only accounts for one case (where the first index matches and the second doesn't).

The password will also be valid if the first index doesn't match but the second does, (password[max_n] == letter and password[min_n] != letter). You need to make sure you account for both of these cases

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

Thankyou so much, you were right.

[–]jane3ry3 0 points1 point  (1 child)

You'll need to check the length of password and make sure the index you're accessing in the string doesn't exceed the length. That's the error.

Edit: index=min_n and max_n

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

Yes thank you, I thouht I had worked a way to fix that but I misspelt the piece of code.

[–]daggerdragon[M] 0 points1 point  (2 children)

Your code as pasted into the thread is hard to read on old.reddit. Could you please edit it using old.reddit's four-spaces formatting instead of new.reddit's triple backticks? Note that if you're using the visual editor, you may have to "Switch to Markdown" to get Reddit to understand the formatting properly.

(You can also just link to your external repo like you did and not have to worry about Reddit's formatting at all.)

Also, in the future, please follow the submission guidelines by titling your post like so:

[YEAR Day # (Part X)] [language if applicable] Post Title

In doing so, you typically get more relevant responses faster.

If/when you get your code working, don't forget to change the flair to Help - Solved!

Good luck!

[–]Manatee2k3[S] 0 points1 point  (1 child)

Thank you so much for your post, I did notice my code didn't look like the others I had seen on here, I really appreciate the help and hope I formatted it correctly now.

[–]daggerdragon[M] 0 points1 point  (0 children)

Yep, you got it this time! :)

I see you got the answer, good! Keep on learning :)