Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions solutions/python/raindrops/1/raindrops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def convert(number):
"""
Converts a number into its corresponding raindrop sounds (Pling, Plang, Plong)
based on divisibility by 3, 5, and 7.
"""

# Start with an empty string to accumulate the sounds.
raindrops = ""

# Check for divisibility by 3.
# We use independent 'if' statements so we can add multiple sounds.
if number % 3 == 0:
raindrops += "Pling"

# Check for divisibility by 5.
if number % 5 == 0:
raindrops += "Plang"

# Check for divisibility by 7.
if number % 7 == 0:
raindrops += "Plong"

# If the string is empty, it means the number was not divisible by 3, 5, or 7.
# In that case, we return the original number as a string.
if not raindrops:
return str(number)
else:
return raindrops