我正在使用python類進行編程的介紹,我們的作業是做99瓶啤酒歌曲。我們還沒有學到了很多東西又是那麼這的確是所有我能想出:試圖在python中編碼99瓶啤酒
def StandardVerse():
print n, "bottles of beer on the wall,", n, ",bottles of beer"
print "take one down pass it around,",n,"bottles of beer on the wall."
def TwoBottles():
print "Two bottles of beer on the wall, two bottles of beer."
print "Take one down pass it around, one bottle of beer on the wall."
def OneBottle():
print "One bottle of beer on the wall, One bottle of beer."
print "Take one down, pass it around, no more bottles of beer on the wall."
def NoBottles():
print "No more bottles of beer on the wall, no more bottles of beer."
print "Go to the store, buy some more, 99 bottles of beer on the wall."
for n in range(99,0,-1):
if n > 2:
print StandardVerse
if n == 2:
print TwoBottles
if n == 1:
print OneBottle
if n <= 1:
print NoBottles
它給了我這個當我運行它
<function StandardVerse at 0x027BEC30>
<function StandardVerse at 0x027BEC30>
<function StandardVerse at 0x027BEC30>
<function StandardVerse at 0x027BEC30>
<function StandardVerse at 0x027BEC30>
<function StandardVerse at 0x027BEC30>
<function StandardVerse at 0x027BEC30>
<function StandardVerse at 0x027BEC30>
<function StandardVerse at 0x027BEC30>
<function StandardVerse at 0x027BEC30>
<function StandardVerse at 0x027BEC30>
<function StandardVerse at 0x027BEC30>
<function StandardVerse at 0x027BEC30>
<function StandardVerse at 0x027BEC30>
<function TwoBottles at 0x027BEC70>
<function OneBottle at 0x027BECB0>
<function NoBottles at 0x027BECF0>
等多達99瓶(爲了空間的緣故,我沒有全部複製。)
我該怎麼做才能打印出真正的歌曲呢?
如果你要打印函數調用然後返回字符串,否則別pting就叫 –