Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Repeatedly Choose Number From List and Lockout Chosen Numbers

I am writing a program for a game I am creating, and I need to get the following:

  1. A number chosen from a range, probably 1-100.
  2. That number printed, will be turned into a display for the user later.
  3. Have that number locked out of being chosen again.

Due to the line of events, I cannot simply get all of the numbers pre-selected, they need to be selected in real time.

from random import *
number = randint(1, 100)

This is what I started with, predictably, but I have nowhere to go.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried using the array module, but I could not figure out how to work it, I am not the best at programming.
I tried using the following:

from random import *
number = randint(1,100)
print(number)
numberstore = number
while numberstore == number:
    number = randint(1,100)
print(number)
numberstore = number

I don’t know how to make this work though.

>Solution :

I think you’re wanting something like this.

from random import *
numberstore = []

while True:
    number = randint(1,100)
    if number not in numberstore:
        numberstore.append(number)
        print(number)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading