[英]Counting the number of vowels
尝试打印编号 元音 运行此代码时,我只得到1,2,3,4
,仅打算打印4。我的错误在哪里,我该如何纠正?
vowels='a','e','i','o','u'
s= 'hellohello'
count = 0
for letters in s:
if letters in vowels:
count+=1
print (count)
您基本上是正确的,但您是在循环中而不是在末尾进行打印。
for letters in s:
if letters in vowels:
count+=1
# de indent to close the loop
print (count)
count
应该不在for
循环中,因此它只打印一次。
vowels='a','e','i','o','u'
s= 'hellohello'
count = 0
for letters in s:
if letters in vowels:
count+=1
print (count)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.