python - 无法在猪拉丁语翻译器上使用输入
问题描述
因此,我正在制作一个猪拉丁语翻译器,以挑战我迄今为止在 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
解决方案
这里只是一个小的更正 - 您必须从终端获取输入并将其分配给一个变量才能使用原始字符串值。所以,如果你这样做,你的翻译应该可以工作
my_input = input("What would you like to convert?")
print (converter(my_input))
推荐阅读
- sql-server - JDBC 和 sqlserver 连接字符串 - 我必须包含端口号吗?
- java - 在 jenkinsx Minikube 中更改 _JAVA_OPTIONS
- c++ - c++ chrono Clock in HH:MM:SS 当它需要在 seconds.milliseconds
- java - 为什么 java 需要强制类型转换才能将有界类型参数实例化为其上限类?
- python-3.x - 将数据框转换为字典并保留所有值
- python - 带有辅助函数的递归二进制搜索返回 None 而不是 True of False
- python - 字符串操作 col_schema="col1 string,col2 int"。我需要检索 => "col1,col2"
- sql - Couchbase JOIN 查询总是返回空结果
- node.js - const fs = require('fs') 在 NW.js 中为空
- amazon-web-services - 如何在android中集成Appsync api