<p>我正在写俄勒冈州小径游戏,这是我的代码,这是造成问题,我不知道为什么会有问题。我想做的是,如果他们输入一个包含列表中某个单词的名称,则会将变量easter_mode设置为1,如果他们不输入,则会将easter_mode设置为0。需要在列表中列出的单词是:(Sturtz,Sturtz,Nate,Nate)
多谢各位</p>
<pre><code>#asking name
player_name = input('What is your name:')
while len(player_name) >= 0:
if len(player_name) > 1:
print("Weclome" + str(player_name))
print('Which mode do you want to play?')
mode_choice = input('(easy) More modes comming soon:')
break
if len(player_name) == 1:
player_name_choice = input(str(player_name)+"? Are you kidding me? Only one letter? You might regreat it (Y/N):")
if player_name_choice == "y" or player_name_choice == "Y":
print("Ok Your Choice!!...")
mode_choice = 'easter'
break
if player_name_choice == "n" or player_name_choice == "N":
player_name = input('What is your name:')
else:
print("You do not type anything, try again")
player_name = input('What is your name:')
#Check Easter Egg Names
easter_names = ["nate sturtz", "Nate Sturtz", "Nate", "nate", "Sturtz", "sturtz"]
if player_name in easter_names:
easter_mode = 1
else:
easter_mode = 0
#easter eggs for name
if easter_mode == 1:
year_set = 2005
mode_choice = 'easter'
else:
year_set = input('Enter a year whatever you like:')
if year_set.isdigit():
return_num = 0
else:
return_num = 1
while return_num == 1:
print('Error,please try again!')
year_set = input('Enter a year whatever you like:')
if year_set.isdigit():
return_num = 0
else:
return_num = 1
year_set = int(year_set)
</code></pre>
<p>当我运行完整文件时,我得到</p>
<pre><code>Traceback (most recent call last):
File "Oregon.py", line 64, in <module>
player_name = input('What is your name:')
File "<string>", line 1, in <module>
NameError: name 'nate' is not defined
</code></pre>
<p>您可以在Github上查看完整代码<br/>
<a href="https://raw.githubusercontent.com/nsturtz/Oregon-Trail/master/Oregon.py" rel="nofollow noreferrer">https://raw.githubusercontent.com/nsturtz/Oregon-Trail/master/Oregon.py</a></p>