Functions: misspelling the arguments

I ran this with no issues (ale vs. ales), until I tried adding variables. Even then, no error was registered. Why?

> def beers_in_house(lagers, ale, mix_culture):

print(f"There are {lagers} lagers in the fridge.")
print(f"We also have {ales} ales available too.")
print(f"There are some {mix_culture} beers in the cellar.")
print("I am getting thirsty!\n")

Thank you!

Stupid question: Did you actually call the function?

yes. After the second run, it would not include the input.

print(“What are the brands of beer?”)
txt = " "
lagers = input("What is the brand of this lager? ")
ales = input("What is the brand of this ale? ")
mix_culture = input("What is the brand of this sour? ")
beers_in_house(lagers, ales, mix_culture)

print(“Are you sure there are no more beers in the fridge?”)
input("?")

lagers2 = input("What is the brand of this other lager? ")
ales2 = input("What is the brand of this other ale? ")
mix_culture2 = input("What is the brand of this other sour? ")
beers_in_house(lagers + " and " + lagers2, ales + " and " + ales2,
mix_culture + " and " + mix_culture2)

Aha. Python doesn’t find ales in your function definition so it uses the variable with the same name in the global scope. If you change the name ales in the first round of inputs it’ll blow.

2 Likes