經過一番研究,我無法找到爲什麼我在此codeacademy練習中得到指定的錯誤(SyntaxError: 'return' outside function
)。「返回外部函數」錯誤
name=input(" input name ")
print("welcome, {}".format (name))
class player():
def __init__(self, atk, hp,):
self.atk=atk
self.hp=hp
def __str__(self):
return "{}, {}".format (self.atk, self.hp)
input("Time for a questionnaire to define your stats")
input("press enter to continue....")
print("in an intense battle when both you and your enemy are on the edge of consciousness and you have a chance to flee do you finish off the opponent taking a chance on being struck down or do you flee with your life?")
statq1=input("fight or flee")
if statq1 == "fight":
return 5+self
elif statq1 == "flee":
return 5+hp
它告訴你'return'是功能之外,因爲它_is_(這就是壞的)。我建議刷新縮進以及'return'語句的具體含義。 – TigerhawkT3
您能否提供一個最簡單的工作示例?您在問題中提供的代碼根本不可用。 – XaF
那我該如何解決這個問題呢? –