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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -