Do not understand what is wrong with the code


#1

Hi,

I am stuck with this particular code for a while now and unable to move ahead. I do not understand what is wrong with the code. Please guide!!!

def hotel_cost(nights):
return 140*nights
def plane_ride_cost(city):
if city == ‘Charlotte’:
return 183
elif city == ‘Tampa’:
return 220
elif city == ‘Pittsburgh’:
return 222
elif city == ‘Los Angeles’:
return 475
else:
return "Enter city again"
def rental_car_cost(days):
rent_cost == 40 * days
if days >= 7:
rent_cost -= 50
elif days >= 3 and days <= 7:
rent_cost -= 20
return rent_cost

The error displayed is: "Did you create a function called rental_car_cost?"
I have defined the function and still this message :open_mouth: It would be great help if you could please guide.


Trip_cost should have only 3 parameters error
#2

your first line in the rental_car_cost function:
rent_cost == 40 * days
you are using == which is for comparison, you should be using only 1 = for assigning, so:
rent_cost = 40*days


#3

Thank you for prompt reply.
I tried using single ‘=’ as well but still the same error message is displayed.

The new code looks like this(same error message getting displayed):

def rental_car_cost(days):
rent_cost = 40 * days
if days >= 7:
rent_cost -= 50
elif days >= 3 and days <= 7:
rent_cost -= 20
return rent_cost


#4

There may be an indentation issue, in a reply if you click the </> symbol you can post your code and it will be formatted. Also if you could provide a link to the exercise there may be something in the instructions that will help


#5

Thank you and as you mentioned I have posted the code below.

def hotel_cost(nights):
  return 140*nights
def plane_ride_cost(city):
  if city == 'Charlotte':
    return 183
  elif city == 'Tampa':
    return 220
  elif city == 'Pittsburgh':
    return 222
  elif city == 'Los Angeles':
    return 475
  else:
    return "Enter city again"
  def rental_car_cost(days):
   	 rent_cost = 40 * days
  if days >= 7:
      rent_cost -= 50
  elif days >= 3 and days <= 7:	
    rent_cost -= 20
  return rent_cost

Below is the link to the exercise (not sure if the link would be accessible but this is a part of ‘Fuctions - Taking a Vacation’ exercise):

https://www.codecademy.com/courses/learn-python/lessons/taking-a-vacation/exercises/transportation-?action=resume&link_content_target=interstitial_lesson


#6

ok, it is an indentation error. On the line that says def rental_car_cost(days), it should further left to match the indentation of the other def lines. And the line below it should move to the left to match the if line below that.


#7

It worked! Thank you so so much. I am fairly new to Python and I am very glad it worked finally! I will make sure to pay extra attention on indentation going forward.


#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.