Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics Functions and Looping Returning Values

Darryl (Kevin) Jones
PLUS
Darryl (Kevin) Jones
Courses Plus Student 5,012 Points

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
8,669 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

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!