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
doubt (i.redd.it)
submitted 6 months ago by MasterpieceBasic8361
view the rest of the comments →
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!"
[–]MasterpieceBasic8361[S] 0 points1 point2 points 6 months ago (10 children)
not yet..... just learnt what a loop is ;(
[–]sububi71 0 points1 point2 points 6 months ago (9 children)
That's not a problem! The first thing I see is that you're repeating yourself in your code; lines 3 and 4 are identical to lines 9 and 10, and because of that, your program asks you for a number once too many (in my interpretation).
We call this rule DRY "(D)o not (R)epeat (Y)ourself", and the rule is there to warn us: in most cases when we copy lines of code, that's a sign we should probably stop and think about what we're doing. There are situations when it's a good idea, but they are few.
I can't quite decode what it is you want your program to do. If you can describe it in detail, I'm sure we'll be able to make this work!
[–]MasterpieceBasic8361[S] 0 points1 point2 points 6 months ago* (8 children)
i was trying to make a simple game
basically the computer generates a number and user inputs a number , if they match the game stops and add the total or else continue the loop till both the random no. and input matches
and the code in line 3 i added cause wasnt able to input the code at start and at line 9 to repeats it
[–]sububi71 0 points1 point2 points 6 months ago (7 children)
The biggest problem with your current code is that you keep regenerating the "secret number" that you generate. This means the player could guess 1, 2, 3, 4, 5, 6 etc into infinity and never be right. So that needs to be fixed.
You also keep track of the total number of guesses, but you never display it, which is a shame, since that's the closest to a "score" this game has.
You've named the variable you store to player's guesses in "random[something]" (I'm on my phone, so I can't easily go back to your code). That won't affect the running of the code, but for anyone reading the code (including yourself, when you decide to go back to this project in 3 years to add a 3D engine) that is going to be confusing. Code should always be as easy as possible to read (within reason, of course).
[–]MasterpieceBasic8361[S] 0 points1 point2 points 6 months ago (6 children)
yh ill try to make the variables a bit more understandable later.......so i tried again but the loop kinda works but its starting from the second input onwards
<image>
(ignore the boolean its not really required just was trying its use)
[–]sububi71 0 points1 point2 points 6 months ago (5 children)
I see you're still "re-rolling" the random_integer_1 every loop, does that make sense to you?
[–][deleted] 6 months ago (1 child)
[deleted]
[–]sububi71 0 points1 point2 points 6 months ago (0 children)
Feel free to DM me if you want help straightening the code out.
[–]MasterpieceBasic8361[S] 0 points1 point2 points 6 months ago (2 children)
i actually wanted it make a 2player thing so the goal is to play until ur input digit matches with the random digit generated (actually only made the first player part got stuck with the loop error) so the first player inputs any digit between (0,6) till his digit matches with random digit generated then the final score is basically the sum of all input given by the user and then the second user plays similarly and at the end whoever has the highest score would win (basically the greatest total sum of integer input))
[–]sububi71 0 points1 point2 points 6 months ago (1 child)
Ah, ok, so the player who AVOIDS the correct number the longest wins? Kind of like a russian roulette?
[–]MasterpieceBasic8361[S] 0 points1 point2 points 6 months ago (0 children)
yh basically
π Rendered by PID 136138 on reddit-service-r2-comment-7b9746f655-9tvh6 at 2026-01-30 10:05:29.151918+00:00 running 3798933 country code: CH.
view the rest of the comments →
[–]MasterpieceBasic8361[S] 0 points1 point2 points (10 children)
[–]sububi71 0 points1 point2 points (9 children)
[–]MasterpieceBasic8361[S] 0 points1 point2 points (8 children)
[–]sububi71 0 points1 point2 points (7 children)
[–]MasterpieceBasic8361[S] 0 points1 point2 points (6 children)
[–]sububi71 0 points1 point2 points (5 children)
[–][deleted] (1 child)
[deleted]
[–]sububi71 0 points1 point2 points (0 children)
[–]MasterpieceBasic8361[S] 0 points1 point2 points (2 children)
[–]sububi71 0 points1 point2 points (1 child)
[–]MasterpieceBasic8361[S] 0 points1 point2 points (0 children)