Я делаю проект для моей школы. Мне нужно принимать вызовы, если вы нажмете кнопку, вы получите случайный вызов, но вы также получите случайный ответ. Я хочу связать вызов с правильным ответом. Я не знаю, как это сделать с помощью индекса, поэтому, если кто-нибудь покажет мне пример того, как это сделать, я буду признателен за это.
Я спросил своих учителей и искал, но ничего не смог найти.
from tkinter import *
import random
theWindow = Tk()
theWindow.geometry('500x500')
theWindow.title('Challenges')
Label(theWindow, text='Press the button below to generate random challenges', bg= 'grey', fg='white').pack()
challenges = ['You are going through Russia. Do you have the item winterjacket?\n \n Option 1: Yes \n Option 2: No',
'A thief grabs your bag with items: What are you going to do?\n\n
Option 1: Not chasing the thief \n Option 2: Chasing the thief',
'You don’t have money for food anymore:\n You found a job for a week. \n Are you going to take the job?:\n\n Option 1: Yes, take the job \n
Option 2: No, you don"t take the job',
'You walk along a grave and hear a sound: \n What are you going to do?: \n \n Option 1: You run away \n Option 2: You take a look',
'You won an helicopter flight and you’re in an helicopter right now. \n The helicopter starts to fall down. \n What are you going to do?: \n \n Option 1: Grab a parachute and jump out of the helicopter \n Option 2: Stay in the helicopter',
'You see an old lady carrying an heavy bag. \n What are you going to do?: \n \n Option 1: Walk away \n Option 2: Help the old lady']
Outcome = ['+10 HP','+10 HP','+10 HP','+10 HP','+10 HP','+10 HP','+10 HP','+10 HP and skip 1 turn', '+20 HP','+20 HP',
'+20 HP','+20 HP', '+30 HP','+30 HP','+30 HP', '+40 HP', '+10 HP + 1 item','+10 HP + 1 item','+10 HP + 1 item',
'+20 HP + 1 item','+20 HP + 1 item', '+20 HP + 2 item', 'Back to 100 HP', 'Nothing happens',
'-10 HP','-10 HP','-10 HP','-10 HP', '-20 HP','-20 HP','-20 HP','-20 HP','-20 HP',
'-20 HP', '-30 HP', 'Lose all HP', '-40 HP', '-50 HP', 'Lose all items', 'Lose all items', 'Skip 1 turn', '-20 HP and skip 1 turn',
'You have to throw the dice: if you get 1, 3 or 5 you can get an item. If you throw 2, 4 or 6 you will get -10 HP damage.',
'Nothing happens']
def challenges_button():
challenge = Label(theWindow, text=random.choice(challenges))
challenge.place(relx=0.5, rely=0.3, anchor=CENTER)
def answers():
answer = Label(theWindow, text= random.choice(Outcome))
answer.place(relx=0.5, rely=0.7, anchor=CENTER)
def answers1():
answer1 = Label(theWindow, text= random.choice(Outcome))
answer1.place(relx=0.5, rely=0.7, anchor=CENTER)
#The buttons
generate_button = Button(theWindow, text='Generate Challenge', height=3,
width=20, command=challenges_button, bg='black', fg='white')
generate_button.place(relx=0.5, rely=0.1, anchor=CENTER)
button_1_Button = Button(theWindow, text='Option 1', height=1, width=20,
command=answers, bg='black', fg='white')
button_1_Button.place(relx=0.5, rely=0.55, anchor=CENTER)
button_2_Button = Button(theWindow, text='Option 2', height=1, width=20,
command=answers1, bg='black', fg='white')
button_2_Button.place(relx=0.5, rely=0.6, anchor=CENTER)
Ожидается: вы нажимаете кнопку «Создать вызов» и получаете правильный ответ. Фактический результат теперь таков, что вы получаете вызов, но случайный ответ, поэтому ответ не верный.