-2

I get a name error saying "bottles" doesn't appear within the functions. How do I get this to work as global variable?

# 100 Bottles of Pop Python

bottles = int(3)

def bottlesOfPop():

    print(bottles, "bottles of pop on the wall, ", bottles, "bottles of pop. "
    "Take 1 down, pass it around, ")
        
    bottles -= 1

    print(bottles, "bottles of pop on the wall.")

def secondlastbottleOfPop():

    print(bottles, "bottles of pop on the wall, ", bottles, "bottles of pop. "
    "Take 1 down, pass it around, ")
        
    bottles -= 1
        
    print(bottles, "bottle of pop on the wall.")

def lastbottleOfPop():

    print(bottles, "bottle of pop on the wall, ", bottles, "bottle of pop. "
    "Take 1 down, pass it around, ")
        
    bottles = 0
        
    print("No more bottles of pop on the wall.")

# Call Function

while bottles > 2:
    bottlesOfPop()

if bottles == 2:
    secondlastbottleOfPop()

if bottles == 1:
    lastbottleOfPop()

print("finish")
Julien
  • 13,986
  • 5
  • 29
  • 53

0 Answers0