Jun-12-2020, 06:22 PM
Hi is there a better way of writing this code instead of writing the repetitive multiple if statements? I'm trying to find a better way of writing this code. Basically I want to count up the the total number of matching letters in the given string s.
s = 'abcdbobbobbegkhl' count = 0 for letter in s: if letter == 'a': count += 1 if letter == 'e': count += 1 if letter == 'i': count += 1 if letter == 'o': count += 1 if letter == 'u': count += 1 print('Number of vowels: ' + str(count))