0
鑑於我構建的這個函數,我收到最後一個返回語句的錯誤,說我無法將它們結合在一起。有另一種方法可以做到這一點嗎?Python3無法連接錯誤?怎麼修?
def simple_pig_latin(input, sep=' ', end='.'):
words=input.split(sep)
Vowels= ('a','e','i','o','u')
Digit= (0,1,2,3,4,5,6,7,8,9)
cons=('b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z')
characters= ('!','@','#','$','%','^','&','*','.')
new_sentence=[]
for word in words:
if word:
if word[0]==" ":
new_word=word
else:
if word[0] in Vowels:
new_word= word+"way"
elif word[0] in Digit:
new_word= word
elif word[0] in cons:
first_letter=word[0] #saves the first letter
change= str(word) #change to string
rem= change.replace(first_letter,'')#remove the first letter
put_last= rem+first_letter #add letter to end
new_word= put_last+ "ay"
elif word[0] in characters:
new_word= word
new_sentence= new_sentence + new_word+ sep
else:
new_sentence.append(word)
return sep.join(new_sentence)+end
我不能使用print語句,只返回@Cyrus –
對不起,打印在那裏進行調試。刪除它,請嘗試。它的作品(只要你期望的輸出是我所得到的(歡迎來到叢林中)。返回作爲elcomeway otay hetay ungle.jay – Cyrus
jay前應該沒有點 –