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
Klaudija Ljevar4,476 Points
Confused about num_tickets and number_of_tickets
I need some help understanding. Why did Craig named: amount_due = calculate_price(num_tickets) and than in function it was different: def calculate_price(number_of_tickets). How come it still works , if you know what I mean?
Nemanja Savkic17,418 Points
I understand it as just a name for the argument and it should be the same in the return line. You can then change the argument that you post inside. def func(x): return x * 3
Alex Kravchenko1,278 Points
@Ryan and Anthony Bednarek, this may be too late but I was confused about this as well. When defining the function, you are putting in the parameters into those parenthesis. It is not the same variable that's in your code. You can name it whatever you want, you just have to put it there and then do something with those parameters below in the function. Once you are using the function in your code, the variables you are putting into the function are arguments. So the function would have worked fine if it was
def calculate_price (mickey_mouse)
return (mickey_mouse * TICKET_PRICE) + SERVICE_CHARGE
#then when the function is called:
final_price = calculate_price (num_of_tickets)
#num_of_tickets is what gets passed into the function
#is the mickey_mouse parameter which gets multiplied by TICKET_PRICE plus SERVICE_CHARGE
#and returns the total price.
The name you put into the parameters doesn't have to be logical or have anything to do with anything. You just put in the most obvious thing you can so you can know what the function is doing and which arguments (variables) will be passed into it. When using your functions, you can put whatever variables in it and it will be what goes into those parenthesis and ran within the function. I don't know if that made sense.
Mustafa Başaran28,046 Points
Hi Klaudijja, The logic is the same as simple algebra. A function may take an argument: f(x) and x may take a value: 4 so, it becomes f(4) Right?
Mustafa's answer doesn't really explain why he created both. Mine runs perfectly fine with just the num_of_tickets.
Hi everybody, the name of the argument could be anything, it would just work inside the function locally. If you want you can keep the same name as well. no issues But the real question is there is no need of argument. The program would work if we do not pass the argument. Why would he do that??? :(
It's something that has confused me as well. If you happen to get an answer can you please post it here?
Would be better if the lecturer could explain the difference between paramenters and arguments. (parameters get passed down to the function when you call the function).
Hi there everybody! I have an issue with this too. If I change num_tickets to number_of_tickets as the teachear does, I have return this error after I put how many tickets I wanna buy. Why this doesn'y happen to the teacher?
Traceback (most recent call last): File "/Users/fedelemairegmailcom/Desktop/Python/Ejercicios/theproject.py", line 19, in <module> amout_due = calculate_price(num_tickets) File "/Users/fedelemairegmailcom/Desktop/Python/Ejercicios/theproject.py", line 6, in calculate_price return num_of_tickets * TICKET_PRICE NameError: name 'num_of_tickets' is not defined