Advertisement
jjessie

99 bottles of beer in recursive python

May 28th, 2011
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. #99 bottles of beer
  4. #in python using a single recursive
  5. #function.
  6.  
  7. def song(n):
  8.     if n >= 2:
  9.         while n > 2:
  10.             print str(n), "bottles of beer on the wall!"
  11.             print str(n), "bottles of beer!"
  12.             print "take one down pass it around"
  13.             print str(n - 1), "more bottles of beer on the wall!\n"
  14.             return song(n - 1)
  15.         print str(n - 1), "bottle of beer on the wall!"
  16.         print str(n - 1), "bottle of beer!"
  17.         print "take one down pass it around"
  18.         print "no more bottles of beer on the wall!"
  19.        
  20. if __name__ == '__main__':
  21.     song(99)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement