首页 > 解决方案 > 无法在猪拉丁语翻译器上使用输入

问题描述

因此,我正在制作一个猪拉丁语翻译器,以挑战我迄今为止在 python 中学到的东西,我已经完成了很多工作,但是每当我尝试使用控制台输入翻译一个单词时,整个过程都会发生狗屎,不工作。有人可以向我解释为什么会这样吗?

代码在下面并与错误一起出现。

input("What would you like to convert?")
#Whole function
def converter (input):
    #variables and their deffnition
    w = str(input)
    word = w.upper()
    x = ((word)[0])
    z = "ay"
    p = "yay"
 # words that start with a vowel
    if x == ("A" or 'E' or 'I' or 'O' or 'U'):
        pyg_word = (word[0] + (word[1:len(word)]).lower() + p)
        return pyg_word

#most words that start with a constant

    elif x == "B" or 'C' or 'D' or 'F' or 'G' or 'H' or 'J' or 'K' or 'L' or 'M' or "N" or 'P' or 'Q' or 'R' or 'S' or 'T' or 'V' or 'W' or 'X' or 'Z':
        pyg_word1 = (word[1] + word[2:len(word)].lower() + word[0].lower()+ z)
        return pyg_word1
    
#Words that start with a Y

    elif x == "Y":
        pyg_word2 = (word[1:len(word)] + word[0].lower() + z)
        return pyg_word2

    elif ((word[0] and word[1] and word[2]) == ("B" or 'C' or 'D' or 'F' or 'G' or 'H' or 'J' or 'K' or 'L' or 'M' or "N" or 'P' or 'Q' or 'R' or 'S' or 'T' or 'V' or 'W' or 'X' or 'Z')):
        pyg_word3 = (word[2:len(word)] + word[0:1] + z)
        return pyg_word3
#othershit
    else:
        fail = "can't convert word yet. please wait"
        return fail   
print (converter(input))

结果:

What would you like to convert?Dogs
Built-in function input><ay

标签: pythoninput

解决方案


这里只是一个小的更正 - 您必须从终端获取输入并将其分配给一个变量才能使用原始字符串值。所以,如果你这样做,你的翻译应该可以工作

my_input = input("What would you like to convert?")
print (converter(my_input))

推荐阅读