網路城邦
上一篇 回創作列表 下一篇   字體:
尋找有幾個母音
2025/11/24 09:13:55瀏覽51|回應0|推薦0

程式碼:

s = input("請輸入一串字串:")

count = 0

for ch in s:

    if ch.lower() in "aeiou":   # .lower() 讓大小寫都能判斷

        count += 1

print("母音有:", count, "個")

功能說明

  • ch.lower():把字元變小寫,A/E/I/O/U 也能偵測

  • in "aeiou":判斷 ch 是否是母音

  • count += 1:計數器加 1

( 興趣嗜好其他 )
回應 推薦文章 列印 加入我的文摘
上一篇 回創作列表 下一篇

引用
引用網址:https://classic-blog.udn.com/article/trackback.jsp?uid=we252668&aid=184302008