【python】Count the vowels in a string.元音数量

# -*- coding: utf-8 -*-
"""
Created on Sat Oct 19 11:42:25 2019

@author: shark
"""


print("This code should compute the number of vowels in a string.")

input_string   =  input( "Enter a string (e.g. your name): " ) 

a = "a"
A = "A"
e = "e"
E = "E"
i = "i"
I = "I"
o = "o"
O = "O"
u = "u"
U = "U"

acount = 0
ecount = 0
icount = 0
ocount = 0
ucount = 0
Acount = 0
Ecount = 0
Icount = 0
Ocount = 0
Ucount = 0


if a in input_string :
     acount = acount + 1
if A in input_string :
     Acount = Acount + 1
if e in input_string:
     ecount = ecount + 1
if E in input_string :
     Ecount = Ecount + 1
if i in input_string :
     icount = icount + 1
if I in input_string :
     Icount = Icount + 1
if o in input_string :
     ocount = ocount + 1
if O in input_string :
     Ocount = Ocount + 1
if u in input_string :
     ucount = ucount + 1
if U in input_string :
     Ucount = Ucount + 1

number_of_vowels = acount+ecount+icount+ocount+ucount+Acount+Ecount+Icount+Ocount+Ucount

print( "The number of vowels in the string is:", number_of_vowels )

 

 

(a) Total number of vowel occurences in a string

To answer this question, you need to write code that will calculate the number of vowels in a string. You should count each occurrence of any vowel and count vowels both in upper and lower case, so a vowel is any of the letters in the string: aeiouAEIOU. (Do not count "y", though it may be used as a vowel, e.g. in "my".)

 

Examples
INPUTOUPUT
yyyykz0
A cat sat on a mat6
Abracadabra5
Eutopia5
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值