Print, loop, Indentation, Python -
i need pit of help. learning python, , have python 2.7.8 looking build simple program count vowels in word. here code:
count = 0 total = 0 v in "bonbon": count += 1 if v == 'e' or v == 'o' or v == 'u' or v == 'a': print('the number of vowel in word ' +str(total))
why print twice? 1- number of vowel 0 , number of 2
could me please? guys
it's printing twice because have print inside of loop. should instead increment total inside loop , print afterwards. if do:
count = 0 total = 0 v in "bonbon": count += 1 if v == 'e' or v == 'o' or v == 'u' or v == 'a': total += 1 print('the number of vowel in word ' + str(total))
it should work.
Comments
Post a Comment