python - 如何创建具有字符串变量类型的列表,然后在条件中使用该列表
问题描述
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)
解决方案
你有错误的论点和错误的顺序in
:
phrase = input("Enter a phrase")
vowels = "aeiouAEIOU"
if phrase[0] in vowels:
print("an {}".format(phrase))
else:
print("a {}".format(phrase))
但是请注意,这过于简单化了。决定使用“a”还是“an”的不是单词拼写的字母,而是单词开头的声音:
- 独角兽
- 一小时
推荐阅读
- python - Kivy 如何在按钮之间切换
- netlogo - Netlogo:我可以期待代理,但偶尔没有人
- python - 如何将按钮放置在 tkinter 的给定框架中?
- mysql - Laravel - 数据库中具有不同字段的不同用户
- tree - 给定一棵树,为每个顶点找到到其他顶点的最长路径
- google-cloud-firestore - 对 Firestore 的调用在 Shell 本地工作,但在部署到 Cloud Functions 后出现空错误
- sql - 显示表之间的关系类型
- php - 如何在 Shopware 5 中注册我的服务和组件?
- javascript - 当我在对象文字中使用 await 时程序如何运行?
- node.js - 将 http 请求转发到 https,req.secure 不起作用