我在這裏絕望。試圖爲我的一個課程做一個程序,並且遇到很多麻煩。我添加了一個輸入循環,因爲部分要求是用戶必須能夠輸入儘可能多的代碼行。問題是,現在我得到了索引超出範圍的錯誤,我認爲這是因爲我打破了停止循環。在python中,我可以在不使用break命令的情況下停止輸入循環嗎?
這裏是我的代碼:
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)
我絕對是一個業餘的和可以使用的所有幫助/意見,我可以得到的。
非常感謝
第一個建議:總是在你的文章中包含完整的錯誤信息。此外,總是說出你想要你的代碼做什麼,並解釋它目前的做法是不同的。 – BrenBarn
「text」變量的定義在哪裏? – GingerPlusPlus