False error on 3/7?


#1

This is my code but it wont let me indent it on here but it is CORRECTLY INDENTED.

def hotel_cost(nights):
  cost = 140 * nights
  return cost
def plane_ride_cost(city):
  if city == "Charlotte":
    ride_cost = 183
    return 183
  elif city == "Tampa":
    ride_cost = 220
    return 220
  elif city == "Pittsburgh":
    ride_cost == 222
    return 222
  elif city == "Los Angeles":
    ride_cost == 475
    return 475
  else:
    return "Cant verify location"

Sorry its not a picture but it was saying I didn’t make a def called plane_ride_cost but I clearly did. Whats wrong with it?


#2

Have you checked the new user category for tips on posting code samples?


#3

I have added an image. Sorry for the inconvenience.


#4

Would it inconvenience you to seek out the new user resources suggested? This topic has been no inconvenience to me, but it is difficult to narrow down the problem when code formatting is not used in posts. There is a way. Do trouble yourself to find it and you will be rewarded by having your future posts immediately meaningful.

A picture can and may contain a thousand words, but when it is code it is very difficult to replicate and means a terrible amount of typing and introduced errors. If we can start with the raw code and then look at pictures afterward, that would be useful all around.


#5

Sorry, I did not know you meant formatting the code. Is this better?

def hotel_cost(nights):
  cost = 140 * nights
  return cost
def plane_ride_cost(city):
  if city == "Charlotte":
    ride_cost = 183
    return 183
  elif city == "Tampa":
    ride_cost = 220
    return 220
  elif city == "Pittsburgh":
    ride_cost == 222
    return 222
  elif city == "Los Angeles":
    ride_cost == 475
    return 475
  else:
    return "Cant verify location"

#6

Ah! Now you have it. Kudos!

We can see and copy your code for testing. Much better.

What comes into question now is why have the `ride_cost variable at all and not just return a value?


#7

Because at first I had that variables so I could do more than was just required but after I got the error message I removed it thinking that maybe it was part of it.


#8

It is working now. By removing the unneeded variable 'ride_cost’s it is now working. Thanks for the help!


#9

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