We can give functions dynamic behavior by passing information when calling them. When we give information to a function, we call this passing arguments. Argument values are assigned to special variables called parameters. Parameter variables store the argument values passed to them. This allows us to use the arguments inside of a function.
argument - Information/data passed to a function
parameter - A variable that receives an argument
def counter(number):
current_number = 1
print(f"Counting from {current_number} to {number}.")
while current_number <= number:
print(current_number)
current_number += 1
def specialGreeting(name):
print(f"Hey there, {name}!")
def specialScolding(name):
print(f"Shame on you, {name}!")
def bottlesSong(beverage, numberOfBottles):
while numberOfBottles > 0:
print(f"{numberOfBottles} bottles of {beverage} on the wall,")
print(f"{numberOfBottles} bottles of {beverage}!")
print("You take one down, pass it around.")
numberOfBottles -= 1
print(f"{numberOfBottles} bottles of {beverage} on the wall!")
# Test out each def by invoking them.
counter(10) # Replace the 10 argument with a different number
specialGreeting("") # Pass your name as an argument
specialScolding("") # Pass your name as an argument
bottlesSong("Pepsi Max", 3) # Replace the arguments with your own values
Counting from 1 to 10.
1
2
3
4
5
6
7
8
9
10
Hey there, Anthony!
Shame on you, Anthony!
3 bottles of Pepsi Max on the wall,
3 bottles of Pepsi Max!
You take one down, pass it around.
2 bottles of Pepsi Max on the wall!
2 bottles of Pepsi Max on the wall,
2 bottles of Pepsi Max!
You take one down, pass it around.
1 bottles of Pepsi Max on the wall!
1 bottles of Pepsi Max on the wall,
1 bottles of Pepsi Max!
You take one down, pass it around.
0 bottles of Pepsi Max on the wall!