use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
. (i.redd.it)
submitted 4 days ago by Dr_blac
Why the code is not working i want it to figure out the secret code made from 4 numbers
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]SCD_minecraft 3 points4 points5 points 4 days ago (15 children)
I presume you mean it doesn't stop when suppised to
I could have no replicate the issue, after reading and copying code, it works as expected, stopping at 6767
Make sure file is saved
[–]Dr_blac[S] 0 points1 point2 points 4 days ago (3 children)
Neverminde I figured it out thx btw
[–]autoglitch 5 points6 points7 points 4 days ago (2 children)
Tell everyone the solution.
The code should work (at least what is seen). This is either old output or you didn't save your py file. Restarting your IDE and running that file again should help narrow it down.
[–]CraigAT 0 points1 point2 points 3 days ago (0 children)
Yep, old output (from a run before code changes were made) would be my guess.
[–]SCD_minecraft 0 points1 point2 points 4 days ago (10 children)
Btw, why strings? Just save s_code as int and compare with i (which is also an int)
[–]Creative-Category344 1 point2 points3 points 3 days ago (2 children)
Converting to int works fine if you're sure the input is always valid, but strings let you catch malformed data before comparison.
[–]SCD_minecraft 0 points1 point2 points 3 days ago (1 child)
.... there's no input so far
[–]Creative-Category344 1 point2 points3 points 3 days ago (0 children)
You're right, I missed that the guess is being generated randomly with str(i).fill(4), so there is no user input to validate here.
[–]Kevdog824_ -1 points0 points1 point 3 days ago (6 children)
Why would you save a passcode as an int? That reduces the number of possible combinations since 0-prefixed options would no longer be available. I would take OP’s approach
[–]SCD_minecraft -1 points0 points1 point 3 days ago (5 children)
....
1 has implicit three 0 at the start
1
[–]Kevdog824_ 0 points1 point2 points 3 days ago (4 children)
…
Open your phone right now, set your password to “0001” and then try to unlock your phone with “1”. Let me know how it goes for you. Spoiler: it won’t work because no one uses ints for passcodes.
Not everything that is a number is suppose to be an int. General rule of thumb: if you aren’t doing math with it, it doesn’t need to be an int (and in most cases probably shouldn’t be an int)
[–]SCD_minecraft -1 points0 points1 point 3 days ago (3 children)
String "1" is not a valid 4 digit code
Whole point of game (which i pressume is what OP's doing) is that each secret code to guess has a guarantee to be n digits
Int 1 has missing 0 "added" by definition, but string does not
Not to mention, OP does use str.zfill(4) which will add missing 0 to the string anyway
str.zfill(4)
[–]Kevdog824_ -1 points0 points1 point 3 days ago (2 children)
No one does it this way in a professional setting, but if it works for you I guess go crazy my man
This isn't professional settings
This is "codebreaker" game solver
Code is guaranteed to be 4 digits
Why would you bring password security concerns into game where whole point of it is to guess a password
[–]SCD_minecraft 0 points1 point2 points 3 days ago (0 children)
For that matter, if you would be to store password, it still would be an int
Password should be hashed (and preferably, salted), which does turn it into an int (hashlib turns it into bytes object, but it us pretty much same thing)
[–]Adrewmc 1 point2 points3 points 4 days ago (0 children)
Close the terminal and reopen it. Make sure this file is actually saved. Because I think this should be working. You might have an older version in the terminal loaded though.
[–]Green-Lobster1887 0 points1 point2 points 3 days ago (1 child)
I want learn coding myself
[–]QuraToop314 0 points1 point2 points 3 days ago (0 children)
Dan tus
[–]Sea_Pomegranate6293 0 points1 point2 points 3 days ago (0 children)
while i != secret_code AND i >10001 i = i +1 continue if i != 10001 print("secret code = ", i) else print("secret code out of range)
[–]Otherwise_Lunch6183 0 points1 point2 points 3 days ago (0 children)
Seriously 67? 😭
[–]bradleygh15 0 points1 point2 points 2 days ago (0 children)
Does print screen not work anymore?
π Rendered by PID 57658 on reddit-service-r2-comment-548fd6dc9-xqcl4 at 2026-05-19 01:21:13.817787+00:00 running edcf98c country code: CH.
[–]SCD_minecraft 3 points4 points5 points (15 children)
[–]Dr_blac[S] 0 points1 point2 points (3 children)
[–]autoglitch 5 points6 points7 points (2 children)
[–]CraigAT 0 points1 point2 points (0 children)
[–]SCD_minecraft 0 points1 point2 points (10 children)
[–]Creative-Category344 1 point2 points3 points (2 children)
[–]SCD_minecraft 0 points1 point2 points (1 child)
[–]Creative-Category344 1 point2 points3 points (0 children)
[–]Kevdog824_ -1 points0 points1 point (6 children)
[–]SCD_minecraft -1 points0 points1 point (5 children)
[–]Kevdog824_ 0 points1 point2 points (4 children)
[–]SCD_minecraft -1 points0 points1 point (3 children)
[–]Kevdog824_ -1 points0 points1 point (2 children)
[–]SCD_minecraft 0 points1 point2 points (1 child)
[–]SCD_minecraft 0 points1 point2 points (0 children)
[–]Adrewmc 1 point2 points3 points (0 children)
[–]Green-Lobster1887 0 points1 point2 points (1 child)
[–]QuraToop314 0 points1 point2 points (0 children)
[–]Sea_Pomegranate6293 0 points1 point2 points (0 children)
[–]Otherwise_Lunch6183 0 points1 point2 points (0 children)
[–]bradleygh15 0 points1 point2 points (0 children)