Home CPSC 110

Lab 6: Bottles of Beverages

 

Objective

To gain experience writing programs using loops and nested control structures.


 

Task

Your task for this lab is to write a program to generate the lyrics to the song "99 Bottles of Beer". However, your program should read in the starting number of bottles the user wants in the song, it won't always be 99.

Also, you can replace "beer" with any other beverage of your choice.


 

Details

  1. Ask the user how many bottles the song should start with. You can assume the user will enter a number 2 or greater.
  2. Create a loop which counts down from that number to 0. For now, just print out the number of bottles to make sure you've got this part right.
  3. Inside the loop, print out 1 verse to the song. Be sure to put in the number of bottles there currently are, and then one less for the second line.
  4. Next put in an if statement to check for when there are 0 bottles. In this case, you should print the last verse which is a bit different (as seen in the example below).

 

Extra Credit

For this lab, there is a chance for extra credit. To get it, you need to make your program use the correct pluralization. Instead of saying "1 bottles", your program should say "1 bottle". This will involve adding a couple more if statements to the program.


 

Example Run

You should test your program with a few different numbers as input and check that the output looks right. Here is an example for the input of 5 (with the extra credit pluralization). I also chose iced tea as my favorite beverage.

Enter the number of bottles to start with: 5
5 bottles of iced tea on the wall, 5 bottles of iced tea.
Take one down and pass it around, 4 bottles of iced tea on the wall.

4 bottles of iced tea on the wall, 4 bottles of iced tea.
Take one down and pass it around, 3 bottles of iced tea on the wall.

3 bottles of iced tea on the wall, 3 bottles of iced tea.
Take one down and pass it around, 2 bottles of iced tea on the wall.

2 bottles of iced tea on the wall, 2 bottles of iced tea.
Take one down and pass it around, 1 bottle of iced tea on the wall.

1 bottle of iced tea on the wall, 1 bottle of iced tea.
Take one down and pass it around, 0 bottles of iced tea on the wall.

0 bottles of iced tea on the wall, 0 bottles of iced tea.
Go to the store and buy some more, 5 bottles of iced tea on the wall.

 

Submitting

When your program is finished, email the .py file to ifinlay@umw.edu.

Copyright © 2021 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.