Python Forum
same number everytime when using random.randint
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
same number everytime when using random.randint
#5
(Aug-23-2019, 09:53 AM)summeringpainting Wrote: Thank you so much newbieAuggie2019! I made the changes you have suggested, it works and finally makes sense to me!

(Aug-23-2019, 08:30 AM)newbieAuggie2019 Wrote: By the way, I guess you are just practising and seeing what your code does, because otherwise, I wouldn't find very interesting a guessing-a-number game, knowing it from the beginning. I mean, you can store the number generated by the program without printing it on the screen. That is to say, I would delete the line
print(luck)
from the real game.

I put it on line 5 to see if the code was checking that number. I wasn't sure if the code chose a different number every time it was run. Now that I know it does stay the same, I decided to take lines 11 and 15 out so it didn't change the number as you suggested.

Thanks again!

I thought so, I also do it to see if everything is working...

You are welcome! Big Grin

By the way, you are saying you took out lines 11 and 15. According to the line numeration as appeared here on your original post, the lines to be taken out are 10 and 14, the ones that say:

        luck = random.randint(1, 3)
Probably at home you have an additional blank line or a comment that makes there the lines 10 and 14 to appear as 11 and 15, but I just wanted to clarify it, just in case...

I'm also learning, and I like to start the easy way and to add other things bit by bit. For instance, you could add now a counter, and make the program tell you something of the sort of: "You are the best! You guessed the number in just "X" tries!", while having fun. Of course, for that, I would change the range to generate a random number from 1 to 20, or from 1 to 50, or from 1 to 100. Even, later on, you could make that a choice of difficulty of the game like easy, medium and difficult. Anything as you are having fun and learning.

All the best,
newbieAuggie2019

"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Reply


Messages In This Thread
RE: same number everytime when using random.randint - by newbieAuggie2019 - Aug-23-2019, 10:22 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  random numbers, randint janeik 2 600 Nov-27-2023, 05:17 PM
Last Post: janeik
  Unexpected output while using random.randint with def terickson2367 1 557 Oct-24-2023, 05:56 AM
Last Post: buran
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,350 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  matrix number assignement to the random indices juniorcoder 4 1,985 Feb-19-2022, 02:18 PM
Last Post: juniorcoder
Sad Iterate randint() multiple times when calling a function Jake123 2 2,112 Feb-15-2022, 10:56 PM
Last Post: deanhystad
  Generate random hex number ZYSIA 1 11,782 Jul-16-2021, 09:21 AM
Last Post: DeaD_EyE
  Using Dictionary to Test Evenness of Distribution Generated by Randint Function new_coder_231013 6 3,354 Feb-23-2021, 01:29 PM
Last Post: new_coder_231013
  Random Number Repeating Tzenesh 5 4,100 Jan-13-2021, 10:00 PM
Last Post: deanhystad
  Random number generator charlottelol 5 3,287 Nov-10-2020, 10:51 PM
Last Post: deanhystad
  Help with a random.randint choice in Python booponion 5 2,856 Oct-23-2020, 05:13 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020