-3

I am making a text adventure game in Python 3 and I am trying to use a random code found in one part of the game and used as a password for the final part of the game but I don't know how to make the random generated code the password. I have the random number generator. How do I make the number that is generated the password.

import random
def code():
     numbers = random.sample(range(10), 4)
     print(''.join(map(str, numbers)))
ssdd
  • 3
  • 3
  • `password=''.join(map(str, numbers))`? – depperm Dec 12 '17 at 21:08
  • 1
    Welcome to SO. Unfortunately this isn't a discussion forum or tutorial. Please take the time to read [ask] and the other links on that page. Invest some time with [the Tutorial](https://docs.python.org/3/tutorial/index.html) practicing the examples. It will give you an idea of the tools Python offers to help you solve your problem. – wwii Dec 12 '17 at 21:09

1 Answers1

0

Make your function not print, but return the code:

def code():
    numbers = random.sample(range(10), 4)
    return ''.join(map(str, numbers))

and in your program, store it to a variable, so that you can both print and query for it:

# ...
password = code()
print(password)
# ...
check = input('Enter password:\n')
if check == password:
    # yeah
user2390182
  • 72,016
  • 6
  • 67
  • 89