简体   繁体   English

如果我的 Python 基于文本的游戏中出现选择错误,如何解决此问题?

[英]How to fix this if choice error in my Python text based game?

I need help with this code;我需要有关此代码的帮助;

input()
print("Created by Mr.StiK")
input()
print('In a dark and creepy cave... You got your consciousness back...')
input()

print("Then you remember... you've no time to waste...")
input()


    
unit = input("Type the command 'wake' to start your adventure... ").lower()
    
while unit.lower() == "wake":

    if unit.lower() == "wake":
        print("And you starts your adventure...")
        break

    if not unit.lower() == "wake":
        print("Sorry, unidentified command. Please type 'wake'")

The error;错误;

When you type the command wrong, it does not say anything, just skips the code.当你输入错误的命令时,它什么也不说,只是跳过代码。

And when we input nothing, we get nothing.当我们什么都不输入时,我们什么也得不到。

And then when we say anything, the program crashes, with this;然后当我们说什么的时候,程序就崩溃了;

Traceback (most recent call last):
  File "<pyshell>", line 1, in <module>
NameError: name 'wake' is not defined 

Please I need help with this.请我在这方面需要帮助。

PS: IF YOU CAN ALSO NEED TO RE-WRITE THE CODE WITH A BETTER CODE/ENGINE, PLEASE, IT WILL BE ACCEPTED TOO. PS:如果您还需要用更好的代码/引擎重新编写代码,请,它也会被接受。

Change your WHILE_LOOP and INPUT to this将您的 WHILE_LOOP 和 INPUT 更改为此

while True:
    unit = input("Type the command 'wake' to start your adventure... ").lower()
    if unit == "wake":
        print("And you starts your adventure...")
        break
    else:
        print("Sorry, unidentified command. Please type 'wake'")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM