Python Forum
Syllable Count Function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syllable Count Function
#1
Create a function that counts the number of syllables a word has. Each syllable is separated with a dash -.

Examples
number_syllables("buf-fet") ➞ 2

number_syllables("beau-ti-ful") ➞ 3

number_syllables("mon-u-men-tal") ➞ 4

number_syllables("on-o-mat-o-poe-ia") ➞ 6

Notes
Don't forget to return the result.
If you get stuck on a challenge, find help in the Resources tab.
If you're really stuck, unlock solutions in the Solutions tab.

This is what I came up with so far:

def number_syllables(word):
	return word.split("-") and word.count(word)
Reply
#2
The string.split() method is going to return a list. You don't need to return the list itself, just the count of items in the list.
Reply
#3
Another approach:

x = "mon-u-men-tal"

Edit:
How many syls and how many dashes can you count?

Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#4
@DPaul, it would be preferred if you didn't give the answer to OP, as he is supposed to figure out the answer by himself with us giving him clues/hints, not the answer directly, as then it won't his effort but the person who wrote the code for him
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  create a function that can count polk203 1 1,666 Apr-12-2020, 12:13 PM
Last Post: ibreeden
  Count Letters in a Sentence (without using the Count Function) bhill 3 5,198 Jun-19-2018, 02:52 AM
Last Post: bhill

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020