Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics Functions and Looping Returning Values

Confused with the outcome of the function in the video...

@9:27 -- I am trying to understand how the function split_check still works even though the first argument in the def is different than in the variable amuount_due.

def split_check(total, number_of_people):
    cost_per_person = math.ceil(total / number_of_people)
    return cost_per_person

total_due = float(input("What is the total? "))
number_of_people = int(input("How many people? "))
amount_due = split_check(total_due, number_of_people)

1 Answer

boi
boi
14,242 Points

You mean;

def split_check(total, number_of_people): 👈#Here the first parameter is "total"
    cost_per_person = math.ceil(total / number_of_people)
    return cost_per_person

total_due = float(input("What is the total? "))
number_of_people = int(input("How many people? "))
amount_due = split_check(total_due, number_of_people)👈#But here when "split_check" function is called, the first 
                                                     #parameter has a different variable "total_due" (this is madness)

First, you need to understand the difference between parameters and arguments

def split_check(total, number_of_people): 👈#Here, there are two PARAMETERS
    cost_per_person = math.ceil(total / number_of_people)
    return cost_per_person

total_due = float(input("What is the total? "))
number_of_people = int(input("How many people? "))
amount_due = split_check(total_due, number_of_people)👈#Here, two ARGUMENTS are given.

"Generally when people say parameter/argument they mean the same thing, but the main difference between them is that the parameter is what is declared in the function, while an argument is what is passed through when calling the function."

argument1 = "Kratos"
argument2 = "Baldur"

def function(parameter1, parameter2):
    return parameter1, parameter2

print(function(argument1, argument2))

Source of information; Stack overflow TerryA

Jason Roberts
Jason Roberts
5,486 Points

Literally thank you, this blew my mind when he ran his code and it worked. I really thought the arguments had to match the parameters to "verify" to get in. Since reading your explanation, I believe you generally want the parameter to describe the value it is taking in while the argument is there to provide context to exactly what kind of value it represents within the scope of the parameter. Like in the previous video when he used the parameter yell(text), and passed through arguments like yell(advice) or yell(help). Thanks so much!