列表下标为整数
def pig_latin(s):text = []
for i in s:
if i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u':
i += 'way'
text.append(i)
else:
n = 1
while 1:
first = i
if i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u':
i = i
i = i + first + 'ay'
text.append(i)
break
n += 1
return text
def main():
s = []
word = str(input('please enter a sentence(with no punctuation):'))
while word != ' ':
s.append(word)
word = str(input('please enter a sentence(with no punctuation):'))
text = pig_latin(s)
print('The result is:')
print(*text, sep=' ')
if __name__ == '__main__':
main()
第十行,n和0都已经是整数了,为什么还报错? 取列表元素目前只支持:
1)单index,如list
2)切片index,如list first = i
页:
[1]