Assigned: Monday, October 7
Due: Thursday, October 17, 2019 by 11:55pm
You will write a program to sing the children's (or maybe young adult) song about bottles of a beverage on a wall, with a twist. You may use whatever beverage you want in the song, just keep it PG-13; I don't want any parents calling me asking why I'm encouraging underage drinking or anything like that.
You may assume the user will enter a whole number (an integer), not a float or a string. However, as it says in the paragraph above, if they enter a negative integer or zero, you must ask them to re-enter it until they fix it.
You may design your program in any way you see fit, but you must include a main function that drives the rest of your program. You should follow the guidelines for good programming that we've discussed in class: using comments, choosing appropriate variable names, making use of functions where appropriate, etc.
How many bottles should we start with? 0 You must start with a positive number of bottles. Please re-enter the number. How many bottles should we start with? -88 You must start with a positive number of bottles. Please re-enter the number. How many bottles should we start with? 10 How many do we take off the wall each time? -1 You must remove a positive number of bottles from the wall. Please re-enter the number. How many do we take off the wall each time? 0 You must remove a positive number of bottles from the wall. Please re-enter the number. How many do we take off the wall each time? 1 10 bottles of pop on the wall, 10 bottles of pop. Take 1 down, pass them around, 9 bottles of pop on the wall. 9 bottles of pop on the wall, 9 bottles of pop. Take 1 down, pass them around, 8 bottles of pop on the wall. 8 bottles of pop on the wall, 8 bottles of pop. Take 1 down, pass them around, 7 bottles of pop on the wall. 7 bottles of pop on the wall, 7 bottles of pop. Take 1 down, pass them around, 6 bottles of pop on the wall. 6 bottles of pop on the wall, 6 bottles of pop. Take 1 down, pass them around, 5 bottles of pop on the wall. 5 bottles of pop on the wall, 5 bottles of pop. Take 1 down, pass them around, 4 bottles of pop on the wall. 4 bottles of pop on the wall, 4 bottles of pop. Take 1 down, pass them around, 3 bottles of pop on the wall. 3 bottles of pop on the wall, 3 bottles of pop. Take 1 down, pass them around, 2 bottles of pop on the wall. 2 bottles of pop on the wall, 2 bottles of pop. Take 1 down, pass them around, 1 bottles of pop on the wall. 1 bottles of pop on the wall, 1 bottles of pop. Take 1 down, pass them around, 0 bottles of pop on the wall.Another run:
How many bottles should we start with? 8 How many do we take off the wall each time? 2 8 bottles of pop on the wall, 8 bottles of pop. Take 2 down, pass them around, 6 bottles of pop on the wall. 6 bottles of pop on the wall, 6 bottles of pop. Take 2 down, pass them around, 4 bottles of pop on the wall. 4 bottles of pop on the wall, 4 bottles of pop. Take 2 down, pass them around, 2 bottles of pop on the wall. 2 bottles of pop on the wall, 2 bottles of pop. Take 2 down, pass them around, 0 bottles of pop on the wall.Another run:
How many bottles should we start with? 10 How many do we take off the wall each time? 3 10 bottles of pop on the wall, 10 bottles of pop. Take 3 down, pass them around, 7 bottles of pop on the wall. 7 bottles of pop on the wall, 7 bottles of pop. Take 3 down, pass them around, 4 bottles of pop on the wall. 4 bottles of pop on the wall, 4 bottles of pop. Take 3 down, pass them around, 1 bottles of pop on the wall.Notice how the last run stops at 1 bottle on the wall, because with taking three down each time, we have to stop there because we don't want to have -2 bottles on the wall.
Your code does not have to follow this exact script verbatim, but all the mentioned functionality should be there: asking the user for number of bottles and how many to remove each time, and printing each verse in turn, stopping before hitting a negative number.
Here's an example you'd use for a function that computes the circumference of a circle:
# This function computes the circumference of a circle. # Parameters: r, the radius of the circle. # Returns: the circumference of the circle. def circumference_of_circle(r): return 2 * math.pi * r
Your program will be graded on correctness, as well as on coding style, which refers to choices you make when writing your code, such as good use of variable names, appropriate indentation,
and comments (this is not an exhaustive list). See the syllabus for further grading details.
You will receive one bonus point for every complete day your program is turned in early, up to a maximum of five points. For instance, if your program is due on September 20 at 11:59pm, if you turn in your code on Moodle any time on September 19 from 12:00am through 11:59pm, you will receive one extra point on your project. Programs submitted on September 18 from 12:00am through 11:59pm will receive two points. This pattern continues for up to five points.