[英]How do I properly use var[0] interpretation
I'm new to Python and trying to make a Pig Latin Translator. 我是Python的新手,并试图制作Pig Latin Translator。 My situation is that the "type" of Pig Latin you use is dependent on where a vowel and/or consonant is at the begging of the word. 我的情况是你使用的Pig Latin的“类型”取决于元音和/或辅音在这个词的乞讨处。 This causes me to use stuff like "my_var[0] = new_var". 这使我使用“my_var [0] = new_var”之类的东西。 My problem is I'm trying to interpret if a variable from a raw input is contains certain string characters, like "a", "x", etc. If anyone could correct my code, as well, that would be awesome! 我的问题是我试图解释原始输入中的变量是否包含某些字符串字符,如“a”,“x”等。如果有人可以更正我的代码,那就太棒了! Thanks for your help in the advance :) ! 感谢您在提前的帮助:)!
print "Hello. Welcome to the Pig Latin translator! :)"# Welcome MSG
eng = raw_input("Please enter in a word in English to translate to Pig Latin.")#Asking the user to input something
if eng[0] == "a" + "b"+"c" :# I'm say if the first letter equals a constant.
Try this 尝试这个
first = eng[0]
rest = eng[1:]
if first in "aeiou":
# is a vowel
else:
# not a vowel, not necessarily a consonant
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.