P ython p rogramming e xercises



Yüklə 1,51 Mb.
Pdf görüntüsü
səhifə62/124
tarix14.05.2023
ölçüsü1,51 Mb.
#113537
1   ...   58   59   60   61   62   63   64   65   ...   124
PythonProgrammingExercisesGentlyExplained

Solution Template 
Try to first write a solution from scratch. But if you have difficulty, you can use the following 
partial program as a starting place. Copy the following code from https://invpy.com/bottlesofbeer-


Python Programming Exercises, Gently Explained 
73 
template.py and paste it into your code editor. Replace the underscores with code to make a working 
program: 
# Loop from 99 to 2, displaying the lyrics to each stanza. 
for numberOfBottles in range(99, 1, ____): 
print(____, 'bottles of beer on the wall,') 
print(____, 'bottles of beer,') 
____('Take one down,') 
____('Pass it around,') 
# If there is only one, print "bottle" instead of "bottles". 
if (numberOfBottles - 1) == ____: 
____('1 bottle of beer on the wall,') 
____: 
print(____ - 1, ' bottles of beer on the wall,') 
# The last stanza has singular "bottle" and a different final line: 
____('1 bottle of beer on the wall,') 
____('1 bottle of beer,') 
____('Take one down,') 
____('Pass it around,') 
____('No more bottles of beer on the wall!') 
The complete solution for this exercise is given in Appendix A and 
https://invpy.com/bottlesofbeer.py. You can view each step of this program as it runs under a debugger at 
https://invpy.com/bottlesofbeer-debug/
Further Reading 
Project #50 in my book, The Big Book of Small Python Projects, also implements this ―99 bottles of 
beer‖ exercise. You can read it for free online at https://inventwithpython.com/bigbookpython/. Project #51 
is a version where the lyrics deteriorate over time with erased letters, swapped letters, and other 
drunken typos. 


74 

Yüklə 1,51 Mb.

Dostları ilə paylaş:
1   ...   58   59   60   61   62   63   64   65   ...   124




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin