程序是否跳过嵌套的while/if代码?

2024-05-05 13:38:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我觉得我已经尽了一切努力让这个工作,但它只是不会运行。。。 我还在学习python,我的课程是从几个月前的秋季开始的。你知道吗

长话短说,我正在用Python制作一个基于文本的“逃离房间”游戏。玩家选择要与之交互的对象,结果会给这些对象提供要使用的项目,直到他们找到解锁门的钥匙为止。为了保护我的理智,它很短很线性。你知道吗

我认为这是我的代码中没有运行的部分,它位于一个大函数中,该函数包含所有4个对象的类似代码(抱歉,如果它有点长)。你知道吗

基本上都是这样,“当他们选择这幅画时,描述它,就像他们想搜索它一样,(1=是,2=否)。你知道吗

如果有,请描述搜索结果。 因为这是故事的最后一个对象(画后面的保险箱有门钥匙),一旦保险箱打开,他们有钥匙,我不想再问他们主要的问题,但它有!?你知道吗

重复的主要问题是

def main_choice_input():
    main_choice = input("""
What would you like to check out? (1=Bed, 2=Desk, 3=Dresser, 4=Painting): """) 
    return main_choice;

#code for describing the objects, the inputs for the player to search them
#and the search results, if tried to name them as self-explanatory as 
#possible

以前的方法是针对其他对象的,这都是在一个大函数中实现的。你知道吗

while main_choice == "4":
    painting_description()
    #painting_input is the "search this?" question
    painting_input = painting_interaction()
    if painting_input =="1":
        painting_search(painting_input,dresser_input)
    if use_key=="1" and painting_input =="1":
       #If they 'used the key' on the desk to get the code:
        painting_search(painting_input,dresser_input)
        unlock = input("""
Would you like to unlock the safe? [1=Yes/2=No]: """)
        if unlock == "1":

            #print (story for opening the safe)

            safe=1 #for ending the game- checking if the safe is open
        if unlock == "2":
           print("""
    That's too bad, let's try again...""")
           main_choice = main_choice_input()
           main_route(main_choice,bed_input,desk_input,dresser_input,
            painting_input,use_key,)
    if painting_input =="2":
        print("""
    The code must be around here somewhere... Let's keep looking!
        """)
       #main_route is the name of this whole function
        main_choice = main_choice_input()
        main_route(main_choice,bed_input,desk_input,
         dresser_input,painting_input,use_key,)
   #I had it re-ask and re-run here too, so if they dont have the code/choose not to search or whatever, they can go back and get it
    break
   while main_choice != "1" or main_choice != "2" or main_choice != "3" or 
main_choice != "4":
    main_choice = main_choice_input()
    main_route(main_choice,bed_input,desk_input,dresser_input,painting_input,use_key,)
 return;

我的问题是,这个程序甚至没有运行unlock=input函数,它播放搜索描述,然后像这样问主“你想签出什么”问题

 Take a look? [1=Yes/2=No]

1

    You walk up and inspect the painting as if it were displayed in a museum.
It's clearly just a copy of the painting, not even trying to be the real thing.
You begin to notice that the painting is hanging a couple inches off the wall...


    You grab the painting on either side of the frame, and gently place it on
the floor, revealing a safe built into the wall!


What would you like to check out? (1=Bed, 2=Desk, 3=Dresser, 4=Painting):

不是最后一个问题,它应该问我是否想打开保险箱,因为我得到了密码,但它没有?为什么?请帮帮我,我很失落很沮丧。你知道吗


Tags: andtheto对象key函数inputsearch