Python 3.x 如何使用random来选择是否要转到奖金问题或不转到奖金问题

Python 3.x 如何使用random来选择是否要转到奖金问题或不转到奖金问题,python-3.x,Python 3.x,出于某种原因,如果我开始这段代码,如果随机选择“否”,它仍然会与“是”一起出现,如果您需要更多详细信息,请询问奖金问题。 它只是在说 import random a = "yes" b = "no" mylist = [a, b] def keuze(): print(random.choices(my_list)) if "yes" in mylist: print("je krijgt

出于某种原因,如果我开始这段代码,如果随机选择“否”,它仍然会与“是”一起出现,如果您需要更多详细信息,请询问奖金问题。 它只是在说

import random

a = "yes"
b = "no"
mylist = [a, b]

def keuze():
    print(random.choices(my_list))
    if "yes" in mylist:
        print("je krijgt een bonus vraag")
        print("Bonus vraag")
        print("In wich year is google launced")
        print("a. 2005")
        print("b. 1995")
        print("c. 1969")
        print("d. 1998")
        answer4 = input("Type here your answer: ")
        if answer4 == "d" or antwoord4 == "D":
            print ("Good your answer is right you get 1 extra chance")
            chance = chance + 1
        else:
            print("Ow sorry, your answer is wrong")
            chance = chance - 1
    else:
         print("The computer didnt chose to give you an bonus question")
example()

这是因为
“yes”
总是在
我的列表中(你在问
“yes”
是否在
[“yes”,“no”]
中)。
您可以尝试将
随机选择(mylist)
结果保存到一个变量中,并测试该变量是否等于
['yes']

我已经尝试过了,但无法得到我需要的结果,因此如果参赛者想要一个奖金问题,我会选择它

像这样

def example():
    print("Do you want an bonus question?")
    bonuss = input("Type here yes or no: ")
    if  bonuss == "yes" or bonuss == "Yes":
        print("U will get an bonus question")
        time.sleep(3)
        print("Bonus question 1")
        time.sleep(2)
        print("In wich year is google launched")
        time.sleep(2)
        print("a. 2005")
        time.sleep(1)
        print("b. 1995")
        time.sleep(1)
        print("c. 1969")
        time.sleep(1)
        print("d. 1998")
        time.sleep(1)
        antwoord4 = input("Type hier je antwoord: ")
        if antwoord4 == "d" or antwoord4 == "D":
            print ("Amazing your answer is right you get 1 extra chance")
            chance = chance + 1
        else:
            print("Ow your answer is wrong")
            chance = chance - 1
    else:
        print("U have chosen to not have an bonus question on to the next question")
example()


问题是我使用了
random.choices(list)
因此,我所做的只是删除
选项的s
而我碰巧看到的列表只是一个字符串
导入时间
随机输入

a = "yes"
b = "no"

list = a, b

rdm = random.choice(list)

def example():
    print(rdm)
    if  rdm == "yes":
        print("U will get an bonus question")
        time.sleep(3)
        print("Bonus question 1")
        time.sleep(2)
        print("In wich year is google launched")
        time.sleep(2)
        print("a. 2005")
        time.sleep(1)
        print("b. 1995")
        time.sleep(1)
        print("c. 1969")
        time.sleep(1)
        print("d. 1998")
        time.sleep(1)
        antwoord4 = input("Type hier je antwoord: ")
        if antwoord4 == "d" or antwoord4 == "D":
            print ("Amazing your answer is right you get 1 extra chance")
            chance = chance + 1
        else:
            print("Ow your answer is wrong")
            chance = chance - 1
    else:
        print("U have chosen to not have an bonus question on to the next question")
example()

首先,你需要学习一些基础知识(编程和python基础知识)…我还在学习python。如果我刚刚得到了解决问题的答案的话