Hello, so I am trying to make a game in Python where you choose from either 1, 2 or 3 and your guess has to be a different number from the random number which can also be 1, 2 or 3. If you guess right you get a point and can play on, however if you fail, then the game ends and your final score is printed to the console / shell window, whatever you want to call it. My game will use Tkinter buttons on a Tkinter window as what the player presses to tell the program their choice. This is Python by the way.
Here is the code:
# door chooser upgraded #setup from tkinter import * from random import randint #functions def bAaction(door): print(door) return door def bBaction(door): print(door) return door def bCaction(door): print(door) return door print ('Door Chooser') havent_opened_wrong_door = True score = 0 chosen_door_num = 0 while havent_opened_wrong_door: evil_door = randint(1, 3) print ('Three doors are ahead...') print ('An evil monster behind one.') print ('Which door do you open?') window = Tk() buttonA = Button(window, text='1', command = lambda *args: bAaction(1, door_num)).pack buttonB = Button(window, text='2', command = lambda *args: bBaction(2, door_num)).pack buttonC = Button(window, text='3', command = lambda *args: bCaction(3, door_num)).pack if door_num == evil_door: print ('BOO!') havent_opened_wrong_door = False else: score = score + 1 print('No monster.') print('Your score is',score) print('You enter the next room...') print('You\'ve been eaten!') print('Game over! You scored', score)
… and this is the error message that shows up on the console / shell window:
if door_num == evil_door: NameError: name 'door_num' is not defined
Also, the Tkinter buttons don’t show up, only the Tkinter window. I’m not sure what the issue is, what I wrote in the title of this forum post likely isn’t correct.
I am a very nooby programmer, and I don’t want to buy the Codecademy Pro subscription to learn from there, so instead I use a book that I already had, and the book doesn’t explain a lot of things such as:
… and more. So in short, I dunno what I’m doing with this Tkinter stuff or any super special things to do with functions.
I have been searching the world wide web for fixes for ages and none of them have worked, so I resorted to a Codecademy forum as it’ll likely help more as the people answering my query can see my code.
Also, don’t mind the ‘upgraded’ stuff, I have this program in another python file but instead it uses the ‘input()’ function, so I’m just upgrading it to use Tkinter buttons.
Thanks for the help.