无效的语法指向python中的“return”

时间:2017-09-10 19:06:02

标签: python python-3.x syntax

我正在探索python的广泛语言。我非常依赖内置的错误欺骗和谷歌搜索我的程序。这次我没有运气。谢谢你的时间!

我正在

  

“第5行的语法无效”

这是我的简单HANGMAN-game

的python代码
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__()

1 个答案:

答案 0 :(得分:3)

您的问题是<input type="checkbox" id="full" /> <div id='Picture_container'> <p>picture container <label for="full">Toggle me full or 700px width</label></p> <div id='thePicture'> <input id="mw100" type="checkbox" /><label for="mw100">toggle image overflow</label> <img src="http://dummyimage.com/1800x1000/00ff00&text=the picture goes here" /> </div> <div id="commentsBox"> <input type="checkbox" id="test" /> <div id="comments"> <label for="test">To show comments- click me!</label> </div> <div id="clickme"> Shown comments here. </div> </div>之前的行缺少其结束方括号return。因此,当您到达第5行时,Python认为您仍然在括号内,并且将]置于括号内是语法错误。

这是一个相当常见的问题 - 如果您在一行看起来很好的语法上出现语法错误,那么查看上一行通常是值得的,并查看您的行是否可能被视为其中的一部分。