Skip to content

Commit

Permalink
improved the code
Browse files Browse the repository at this point in the history
  • Loading branch information
its-ChaTTy committed Apr 22, 2024
1 parent 703fe69 commit 6976aa2
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions practice/raindrops/raindrops.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,41 @@
def convert(number):
sounds =[]
if number%3==0:
"""
Convert a number into a string that contains raindrop sounds corresponding to certain potential factors.
A factor is a number that evenly divides into another number, leaving no remainder.
The simplest way to test if one number is a factor of another is to use the modulo operation.
The rules of raindrops are that if a given number:
- has 3 as a factor, add 'Pling' to the result.
- has 5 as a factor, add 'Plang' to the result.
- has 7 as a factor, add 'Plong' to the result.
- does not have any of 3, 5, or 7 as a factor, the result should be the digits of the number.
Args:
number (int): The number to be converted into a raindrop sound string.
Returns:
str: The resulting raindrop sound string.
Examples:
>>> convert(28)
'Plong'
>>> convert(30)
'PlingPlang'
>>> convert(34)
'34'
"""
sounds = []

if number % 3 == 0:
sounds.append('Pling')
if number%5==0:
if number % 5 == 0:
sounds.append('Plang')
if number%7==0:
if number % 7 == 0:
sounds.append('Plong')
if len(sounds)==0:

if len(sounds) == 0:
return str(number)
else:
return "".join(sounds)

return "".join(sounds)

0 comments on commit 6976aa2

Please sign in to comment.