Skip to content

Feat/water day python solution -> main#17

Open
alangnt wants to merge 2 commits intocodedex-io:mainfrom
alangnt:feat/water-day-python-solution
Open

Feat/water day python solution -> main#17
alangnt wants to merge 2 commits intocodedex-io:mainfrom
alangnt:feat/water-day-python-solution

Conversation

@alangnt
Copy link
Copy Markdown
Contributor

@alangnt alangnt commented Mar 22, 2026

Hi Codédex team,

This PR adds a working Python solution for today's Water Day 💧 challenge, and updates the README to add a link for the challenge.

Here's the code :

def leaky_pipe(volume, leak, hours, threshold):
  # for each passing hour
  for i in range(hours):
    # we calculate the new volume based on the formula
    volume = volume * (1 - leak / 100)

    # check if treshold
    if volume < threshold:
      # if volume less than threshold, it failed
      return -1

  # otherwise we return the new volume
  # once the loop is over, rounded by 2 decimals
  return round(volume, 2)

Here's how it works :

  • for each hour that has passed, we calculate the new volume using the given formula
  • if the new volume is below the threshold, that means it failed before time is up, so we return -1
  • otherwise we return the new volume rounded by 2 decimals once the loops is over

Have a nice day !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant