首页 > 解决方案 > 如何创建具有字符串变量类型的列表,然后在条件中使用该列表

问题描述

phrase = input["Enter a phrase: "]
vowles = ("a","e","i","o","u","A","E","I","O","U")

if (vowles) in (phrase[0:1]):
    print("an"+phrase)
else:
    print("a" + phrase)

标签: python

解决方案


你有错误的论点和错误的顺序in

phrase = input("Enter a phrase")
vowels = "aeiouAEIOU"
if phrase[0] in vowels:
    print("an {}".format(phrase))
else:
    print("a {}".format(phrase))

但是请注意,这过于简单化了。决定使用“a”还是“an”的不是单词拼写的字母,而是单词开头的声音:

  • 独角兽
  • 一小时

推荐阅读