← Back to challenges

Syncopated Rhythm

PythonHardstringsloopsvalidation

Instructions

Syncopation means an emphasis on a weak beat of a bar of music; most commonly, beats 2 and 4 (and all other even-numbered beats if applicable).

You will be given a string representing beats, where hashtags # represent emphasized beats. Create a function that returns if the line of music contains any syncopation, and False otherwise.

Examples

has_syncopation(".#.#.#.#") ➞ True
# There are Hash signs in the second, fourth, sixth and
# eighth positions of the string.

has_syncopation("#.#...#.") ➞ False
# There are no Hash signs in the second, fourth, sixth or
# eighth positions of the string.

has_syncopation("#.#.###.") ➞ True
# There is a Hash sign in the sixth position of the string.

Notes

All other unemphasized beats will be represented as a dot.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Fruit Juices