# FAQ: Introduction to Functions - Multiple Parameters

This community-built FAQ covers the “Multiple Parameters” exercise from the lesson “Introduction to Functions”.

Paths and Courses
This exercise can be found in the following Codecademy content:

## FAQs on the exercise Multiple Parameters

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

## Join the Discussion. Help a fellow learner on their journey.

You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like () to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

In case anyone else gets confused here. In the lesson it teaches to define a function we type
def function_name(parameter1, parameter2, parameter 3)
when running this you will run into a syntax error. simply retype to match this
def function_name(parameter1, parameter2, parameter 3):
not having the colon will cause a syntax error to appear

4 Likes

I’m wondering why the solution requires a space between hotel_rates and the comma. Anyone else come into this issue?

5 Likes

def calculate_expenses(plane_ticket_price , car_rental_rate , hotel_rate , trip_time):
car_rental_total = car_rental_rate * trip_time
hotel_total = hotel_rate * trip_time-10
print(car_rental_total + hotel_total + plane_ticket_price)
calculate_expenses(200, 100, 100, 5)

1 Like

Did you forget to indent when defining the function?

6 Likes

Can anyone explain to me few moments please?

1.Why we should do here the multiply action?
car_rental_total = car_rental_rate * trip_time

2. Why the output will be different if write the code not this way

hotel_total = hotel_rate * trip_time - 10

but this:

hotel_total = hotel_rate * trip_time
hotel_total =- 10

1 Like

1: You multiply because the car_rental_total variable is to represent the total cost of renting the car. Industry standard for car rental businesses is to charge clients on a hourly rate. In order to get a cost of a rental, it would require you to multiply the rate (price for renting) by the amount of time the car was used.

2: ‘=’ assigns a meaning to a variable. In your alternative way, by writing hotel_total = -10 you are making the variable literally -10, you arent reducing the total by 10.

By by using hotel_total = a second time, you are rewriting its meaning.

By doing it all in one line:

hotel_total = hotel_rate * trip_time - 10

It will now calculate ‘hotel_rate * trip_time - 10’ together to accurately make the hotel_total variable represent the total cost of the hotel stay.

I hope this explanation helps.

2 Likes

I got it.
Thank you a lot for your explanation!

1 Like

I as a practice always use parenthesis when doing multiple calculations. I really think it should be

(hotel_rate * trip_time) - 10

Or at least it should be considered a valid answer. I know there is an order of how the +, _ * / work, but I don’t think I’ll remember them. I just know that hotel_rate * (trip_time - 10) would be very different than the answer you are wanting to get.

The other thing I don’t really understand is that I did
print(str(car_rental_total + hotel_total + plane_ticket_price))
and it wasn’t considered valid? I suppose I only have to use str when mixing different data types?

Thanks,
Halimah

2 Likes
``````def calculate_expenses(plane_ticket_price, car_rental_rate, hotel_rate, trip_time):
car_rental_total = car_rental_rate * trip_time
hotel_total = hotel_rate * trip_time - 10
print(car_rental_total + hotel_total + plane_ticket_price)
calculate_expenses(200, 100, 100, 5)
``````

Hi, everything in this code is fine, but I just wanna ask why we do not need to add str( ) for the parameters in the print statement. Is it because we only use str( ) for printing variables that have numbers assigned to them, and we dont need to use str( ) for parameters?

There’s a couple of things on the go here so I’ll try and break it down. You may have seen simple `print` statements like `print(3)` before. Part of the machinery of `print` will try and get a string representation of this integer object so that `print(str(3))` would have the same output as `print(3)`.

So no, you don’t have to convert everything to a string before using `print` because it will do some of the formatting for you.

The other part of this is that expression using `+` operators is evaluated before being passed to `print`. So your call acts much the same as the following would-

``````temp = car_rental_total + hotel_total + plane_ticket_price
print(temp)
``````

We know this is fine because we’re adding together three integers so we just get the sum of those integers as a new integer (and print does the formatting of that new integer for us).

You may have seen similar things that looked more like `print('some string' + str(number))`. If you consider what happens before the argument is ever passed to `print` then this makes sense.

``````# both of these will fail for slightly different reasons
text = '3' + 3
number = 3 + '3'
``````

We cannot concatenate a string with an integer like this, or vice versa (we’d get a type error). So we may convert the integer to a string `str(3)` and then join it to the other string in which case we pass a single string to `print` and everything makes sense again.

``````temp = '3' + str(3)
print(temp)
Out: 33  # this is a string after all, it's just two characters
``````
1 Like

Hi guys,

I don’t get it. This is my code:

def calculate_expenses(plane_ticket_price, car_rental_rate, hotel_rate, trip_time)
car_rental_total = car_rental_rate * trip_time
hotel_total = hotel_rate * trip_time - 10
print(car_rental_total + hotel_total + plane_ticket_price)

calculate_expenses(200, 100, 100, 5)

In Question 5 it says that the result is 1190. But I get a syntax error…WHY? What is wrong?

Hi!

Just wondering if someone can let me know if this is an acceptable way to pass this lesson, any other ways it can be improved would be appreciated as it would help my learning.

``````# Write your code below:
def calculate_expenses(plane_ticket_price, car_rental_rate, hotel_rate, trip_time):
car_rental_total = car_rental_rate * trip_time
hotel_total = hotel_rate * trip_time - 10
trip_total = car_rental_total + hotel_total + plane_ticket_price
print("Hello! The cost of car rental for the trip is " + str(car_rental_total) + ". The hotel rate will be " + str(hotel_total) + ". Finally, your ticket price is " + str(plane_ticket_price) + ".")
print("The total cost of your trip would be " + str(trip_total))

calculate_expenses(200, 100, 100, 5)
``````

Hello,

Hopefully you managed to pass this lesson by now, but I thought I would reply to help you and anyone else who maybe comes across this issue.

I tested your code and the Syntax Error is on the first line where you are defining your function. You must end the function parameters with a colon. I believe this will solve the issue.

In the example code below, I also created a variable trip_total to hold the value of the calculation in your print statement.

``````def calculate_expenses(plane_ticket_price, car_rental_rate, hotel_rate, trip_time):
car_rental_total = car_rental_rate * trip_time
hotel_total = hotel_rate * trip_time - 10
trip_total = car_rental_total + hotel_total + plane_ticket_price
print(trip_total)

calculate_expenses(200, 100, 100, 5)
``````

Hope this helps!

Evening,

I’m starting to find it a little difficult so thought I’d post my progress. The bot reporting if you’re right or wrong has thrown me a couple of times.

hotel_total=(hotel_rate * trip_time)-10

I wrote this calculation with parenthesis and I was told it was incorrect. It still gives the same answer without parenthesis.

In Part 4 you’re instructed to:

Lastly, let’s print a nice message for our users to see the total. Use print to output the sum of `car_rental_total` , `hotel_total` and `plane_ticket_price` .

However if you include any text before the string it tells you that you’ve made an error.

print("Your total is " + str(car_rental_total + hotel_total + plane_ticket_price))

I might be wrong but that was my experience. I’ve passed the lesson now and I feel like I learned some things.

Thanks.

Can anyone help me troubleshoot this error?

Code:
def calculate_expenses(plane_ticket_price, car_rental_rate, hotel_rate, trip_time):
car_rental_total = car_rental_rate * trip_time
hotel_total = hotel_rate * trip_time-10
print(car_rental_total + hotel_total + plane_ticket_price)
calculate_expenses(200, 100, 100, 5)

Error:
Traceback (most recent call last):
File “travel.py”, line 6, in
print(car_rental_total + hotel_total + plane_ticket_price)
NameError: name ‘car_rental_total’ is not defined

Please view How do I format code in my posts? as without it code loses formatting and more importantly indentation.

Make sure any statements that are part of your function are indented to the same level as the function, especially if they use function local names that are forgotten once the function has finished executing.

For example the following perfectly valid-

``````def func():
x = 3
print(x + 2)
return x

print(func())
Out: 3
``````

Whereas this will fail because there is no x in the outer scope (the `x` is local to the function, the function itself is denoted by its indentation and `print` is back in the outer scope).

``````def func():
x = 3

print(x)  # ERROR
``````

I have a problem with the way the coupon is used.
Wouldn’t you want to edit the fuction as little as possible?
If the coupon price would change the fuction will always lower the price by 10 no matter what the coupon says.
If you make a new variable called “coupon” doesn’t that make it easier to change the coupon price?

# Write your code below: def calculate_expenses(plane_ticket_price, car_rental_rate, hotel_rate, trip_time): car_rental_total = car_rental_rate * trip_time hotel_total = hotel_rate * trip_time - coupon print(car_rental_total + hotel_total + plane_ticket_price) coupon = 10 calculate_expenses(200, 100, 100, 5)
1 Like

In exercise 5 in this lesson, when I type the print statement in the following

def calculate_expenses(plane_ticket_price, car_rental_rate, hotel_rate, trip_time): car_rental_total = car_rental_rate * trip_time hotel_total = hotel_rate * trip_time - 10 print("Your total is: \$", car_rental_total + hotel_total + plane_ticket_price) calculate_expenses(200, 100, 100, 5)

it prints a space between the \$ and the total. How do I remove this space, as there is no space in the string “Your total is: \$” This is not really neccesary, but I was just wondering how to do it.

1 Like

Yes do not forget about the : colon at the end of ever def function you do. It’s very important.