I am 15 and currently doing a GCSE in Computing. My knowledge is very basic and I've had a bit of trouble with a piece of code I have to write for a 'Vowel Worth Calculator' which is supposed to check through a word and give it a vowel score depending on how many and which vowels it has. I keep getting an error, and I am completely stumped, any help would be appreciated. Here is my source code :
Vowel Worth Counter
print('Welcome to the Vowel Worth Counter!')
word = input('Please input your word, in lower-case, or type Q to quit.')
if word == 'Q' :
quit()
def vowelcount(word) :
lettercount = int(len(word))
vowelscore = 0
checkcount = 1
position = 0
while lettercount != checkcount :
if word[position] == str('a') :
vowelscore = vowelscore + 5
if word[position] == str('e') :
vowelscore = vowelscore + 4
if word[position] == str('i') :
vowelscore = vowelscore + 5
if word[position] == str('o') :
vowelscore = vowelscore + 5
if word[position] == str('u') :
vowelscore = vowelscore + 5
position = position + 1
if lettercount == checkcount :
print('I have finished calculatiing your Vowel Score.')
print('Your Vowel score is ' + str(vowelscore) + '!')
for x in range (0,1) :
break
vowelcount(word)
As I said, any help would be appreciated, thank you.
checkcount, so yourwhileloop can never end.while lettercount != checkcount. You never alter either in your while loop, while you still incrementposition. This is why you're code is dyingfor letter in word:would be the Pythonic idiom, at least if I weren't going to use more advanced constructions.