我正在尝试编写Pig latin翻译器并遇到以下错误:
line 37, in <module>
for i in word:
NameError: name 'word' is not defined
当我尝试运行此程序时。
以下是相关代码:
def Pig_word0 (word):
"" "This is a function which can make string translate to pig latin and first letter become capital." ""
# Determined string include a, e, i, o, u or not
Prefix = []
for i in word:
if i in "aeiouy":
break
else:
Prefix.append (i)
任何提示赞赏。谢谢。
答案 0 :(得分:1)
这里的问题是,解释器假设您的代码是两个独立的块
1)def Pig_word0(字): &#34;&#34; &#34;这是一个功能,可以使字符串转换为猪拉丁语,第一个字母成为大写。&#34; &#34;&#34;
2)
# Determined string include a, e, i, o, u or not <br/>
Prefix = []
for i in word:
if i in "aeiou":
break
else:
Prefix.append (i)
所以,正确缩进代码并检查