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

Returning Values Check Please activity

I am just looking this over and was confused when reading the code again. How come when defining "split_check" we put (total, number_of_people). But when working on the wording of the coding we put total_due = float(input) etc etc and not "total" instead? Why do we change it from "total" to "total_due"?

import math

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)

print("Each person owes ${}".format(amount_due))

1 Answer

Megan Amendola
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Megan Amendola
Treehouse Teacher
import math

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)

print("Each person owes ${}".format(amount_due))

total is the argument being passed into the split_check method. It can only be used inside of that function. total_due is a variable that holds a float with the total amount due for the meal. This is then passed into the function below as the total argument for the function along with the variable for the number of people: amount_due = split_check(total_due, number_of_people)

If you want, you can change the name of total_due in the two places it appears to total and everything would still work the same. They are just variable names.