| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
- def pig_latin(s):
 
 -     text = []
 
 -     for i in s:
 
 -         if i[0] == 'a' or i[0] == 'e' or i[0] == 'i' or i[0] == 'o' or i[0] == 'u':
 
 -             i += 'way'
 
 -             text.append(i)
 
 -         else:
 
 -             n = 1
 
 -             while 1:
 
 -                 first = i[0, n]
 
 -                 if i[n] == 'a' or i[n] == 'e' or i[n] == 'i' or i[n] == 'o' or i[n] == 'u':
 
 -                     i = i[n:]
 
 -                     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[0] 
2)切片index,如list[0:10] 
 
 
 |   
 
 
 
 |