-5

这是我的猪拉丁语翻译器代码。它适用于 Code academy 和 linux 终端。

pyg = 'ay'
new_word = pyg

original = raw_input('Enter a word: ')

if len(original) > 0 and original.isalpha():
    original.lower()
    word = original
    first = original[0]
    if first  == 'a' or first =='e' or first == 'i' or first =='o' or first == 'u':
        print 'vowel'

    elif first != 'a' or first !='e' or first !='o' or first !='i' or first !='u':


        print  word.lower()[1:] + first +new_word 

else:
    print 'empty'

代码学院给出以下结果;糟糕,再试一次!您的单词以辅音开头,但打印的是“ay”而不是“ogday”。确保正确的值#存储在“new_word”中。

“ay”不打印,但“ogday”打印。

有谁知道如何解决这一问题?如果不解决这个问题,我就无法继续使用 Codeacademy。

4

2 回答 2

0

例如,您可以执行类似的操作。您走在正确的轨道上,只需使用您在代码学院中学到的知识来完成这项任务。

consonants = "bcdfghjklmnpqrstvxz"
original = raw_input('Enter a word: ')

if len(original) > 0 and original.isalpha():
   if original.lower()[0] in 'aeiou':
      print original.lower() + 'ay'
   else:
      keep_first_consonants = ''
      count = 0
      for letter in original.lower():
          if letter in consonants:
             keep_first_consonants = keep_first_consonants + letter
             count += 1
          else:
             break
      total_characters = len(original.lower())
      print original.lower()[count:total_characters] + keep_first_consonants + 'ay'
else:
    print 'Accept only letters'
于 2013-09-01T21:16:27.650 回答
0

当您点击运行时,codeacademy 课程检查器似乎会检查变量 new_word

所以你只需要为你的两个打印变量使用 new_word

此代码有效:

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    word = original.lower()
    first = word[0]
    if first == "a" or first == "e" or first == "i" or first == "o" or first == "u":
        new_word = original + pyg
        print new_word
    else:
        newer_word = word[1:]
        new_word = newer_word + first + pyg
        print new_word
于 2013-10-01T01:24:36.987 回答