Skip to content

Instantly share code, notes, and snippets.

@Kwisses
Created March 4, 2016 19:02
Show Gist options
  • Save Kwisses/e5392426774a88521e27 to your computer and use it in GitHub Desktop.
Save Kwisses/e5392426774a88521e27 to your computer and use it in GitHub Desktop.
[Daily Challenge #8 - Easy] - 99 Bottles of Beer on the Wall - r/DailyProgrammer
# ***** DAILY CHALLENGE 8 - EASY *****
# Write a program that will print the song "99 bottles of beer on the wall".
#
# for extra credit, do not allow the program to print each loop on a new line.
# ---------------------------------------------------------------------------------------------------------------------
def bottles_song():
"""Outputs the song '99 bottles of beer on the wall'.
Return:
str: A string that contains the whole song; one line.
"""
bottles = 99
output = []
while bottles >= 0:
if bottles == 2:
output.append("2 bottles of beer on the wall, 2 bottles of beer. Take one down pass it around, "
"1 bottle of beer on the wall.")
elif bottles == 1:
output.append("1 bottle of beer on the wall, 1 bottle of beer. Take one down pass it around, "
"now there's no more bottles of beer on the wall.")
elif bottles == 0:
output.append("No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy "
"some more, 99 bottles of beer on the wall.")
else:
output.append("%s bottles of beer on the wall, %s bottles of beer. Take one down, pass it around, "
"%s bottles of beer on the wall." % (bottles, bottles, bottles - 1))
bottles -= 1
return ' '.join(output)
song = bottles_song()
print(song)
@Kwisses
Copy link
Author

Kwisses commented Mar 4, 2016

[Daily Challenge #8 - Easy] from the DailyProgrammer subreddit. 99 Bottles of Beer on the Wall. Included bonus; output on one line.

Reference: https://www.reddit.com/r/dailyprogrammer/comments/pserp/2162012_challenge_8_easy/

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