我在这里很绝望。试图为我的一门课做一个程序,但遇到了很多麻烦。我添加了一个输入循环,因为部分要求是用户必须能够输入任意多的代码行。问题是,现在我得到索引超出范围的错误,我认为这是因为我正在打破以停止循环。
这是我的代码:
print ("This program will convert standard English to Pig Latin.")
print("Enter as many lines as you want. To translate, enter a blank submission.")
while True:
textinput = (input("Please enter an English phrase: ")).lower()
if textinput == "":
break
words = textinput.split()
first = words[0]
way = 'way'
ay = 'ay'
vowels = ('a', 'e', 'i', 'o', 'u','A', 'E', 'I', 'O', 'U')
sentence = ""
for line in text:
for words in text.split():
if first in vowels:
pig_words = word[0:] + way
sentence = sentence + pig_words
else:
pig_words = first[1:] + first[0] + ay
sentence = sentence + pig_words
print (sentence)
我绝对是一个业余爱好者,可以使用我能得到的所有帮助/建议。
非常感谢