0
我的代碼:Python字符串和Piglatin
def isVowel(character):
vowels = 'aeiouAEIOU'
return character in vowels
def toPigLatin(String):
index = 0
stringLength = len(String)
consonants = ''
if isVowel(String[index]):
return String + '-ay'
else:
consonants += String[index]
index += 1
while index < stringLength:
if isVowel(String[index]):
return String[index:stringLength] + '-' +consonants + 'ay'
else:
consonants += String[index]
index += 1
return 'This word does contain any vowels.'
def printAsPigLatin(file):
return toPigLatin(file)
程序必須要求一個文件名,以將其轉換爲piglatin。該文件每行包含一個字。如何使用我的printAsPigLatin
函數向用戶詢問文件名以將其轉換爲明膠片?
這看起來很像CodeAcademy上的類似問題 –