gpt4 book ai didi

Python/字符串/辅音

转载 作者:行者123 更新时间:2023-11-28 19:40:28 32 4
gpt4 key购买 nike

我正在努力思考如何在句子中表示辅音。我刚才使用的代码似乎无法完成这项工作:

vowels = ("aeiou")
count = 0
for x in text:
if not x in vowels:
count += 1

在示例“hello world”作为输入时,我收到 8 个辅音。非常感谢。

最佳答案

你最好直接检查辅音,而不是“不是元音,不是空格,不是标点符号和...”

consonants = "bcdfghjklmnpqrstvwxyz"
count = 0
for x in text:
if x in consonants:
count += 1

关于Python/字符串/辅音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10289761/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com