I'm trying to make my basic syllable counter run through multiple words, but I do not know how to do so without error. In the code below, I made a placeholder variable containing two words for the code to count syllables of. However, the code ends up not functioning and creates no output. Anyone know what to do?
new_variable = "WORD", "AGAIN"
def syllable_count(word):
word = word.lower()
count = 0
vowels = "aeiouy"
if word[0] in vowels:
count += 1
for index in range(1, len(word)):
if word[index] in vowels and word[index - 1] not in vowels:
count += 1
if word.endswith("e"):
count -= 1
if word.endswith("le"):
count += 1
if word.endswith("ia"):
count += 1
if count == 0:
count += 1
if word.endswith("management"):
count -= 1
if word.endswith("announcement"):
count -= 1
return count
print(syllable_count(new_variable))
As @TimRoberts mentioned in the comments. You are passing a tuple instead of a string to your syllable_counter
function.
All you need to do is iterate through the tuple ie new_varieble
and then call your syllable_counter
for each value.
Just remove your last line and write these two:
for word in new_variable:
print(syllable_counter(word))
new_variable = "WORD", "AGAIN"
print(new_variable)
('WORD', 'AGAIN')
You could try to iterate through the list of new_variable instead, for example:
for new_variable in ["WORD", "AGAIN"]:
print(syllable_count(new_variable))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.