Hun*_*inh 0 python syntax python-3.x
我只是在探索的广泛语言python。我在很大程度上依靠内置的错误检测和谷歌搜索来调试程序。这次我没有运气。感谢您的时间!
我正进入(状态
“第5行的语法无效”
这是我的简单的python代码HANGMAN-game:
import random
def __secretword__():
secret_word = word_list[random.randomint(len(word_list))
return secret_word #THIS IS LINE 5
def __ask__():
ans = input("Would you like to play more? (yes/no): ")
if ans == "yes"
__secretword__()
else:
print(":(")
__secretword__()
word_list = ["nei", "brun", "ja", "smile", "glad", "gal"]
secret_word = secret_word
sw_list = list(secret_word)
guess_lines = ["_"] * len(secret_word)
mistakes = []
lives = 2 * len(secret_word)
print(guess_lines)
user_guess = input("Guess a letter: ")
while(lives != 0)
if user_guess in sw_list:
i = sw_list.index(user_guess)
del guess_lines[i]
guess_lines.insert(i, user_guess)
print(guess_lines)
print("Lives: ", lives)
print("Mistakes: ", mistakes)
if "_" not in guess_lines:
break
else:
mistakes.append(user_guess)
print(guess_lines)
lives = lives - 1
print("Lives: ", lives)
print(mistakes)
__ask__()
Run Code Online (Sandbox Code Playgroud)
您的问题是,前一行return缺少其右方括号]。因此,Python认为进入第5行时您仍在方括号内,而放在return方括号内是语法错误。
这是一个相当普遍的问题-如果您在看起来不错的行上遇到语法错误,通常值得去看一下前一行,看看您的行是否被认为是其中的一部分。
| 归档时间: |
|
| 查看次数: |
7782 次 |
| 最近记录: |