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?
Mustafa Başaran28,018 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?
It's something that has confused me as well. If you happen to get an answer can you please post it here?
Mustafa's answer doesn't really explain why he created both. Mine runs perfectly fine with just the num_of_tickets.
Nemanja Savkic17,402 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,270 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.
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??? :(
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).
Federico Lemaire2,543 Points
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