5. Pull it together


#1
I have been stuck on this for days.  I slept on this and found no answer in my head while away.  I tried going for walks etc.  The output for the error is:

Traceback (most recent call last):File "python", line 17, in
NameError: name 'days' is not defined

I thought days **is** defined since it was defined and a argument.  Also I would like to properly link this as others have done with the numbers for each line of coding.  How do I do that?

def hotel_cost(days):
return 140 * days
def plane_ride_cost(city):
if city == "Charlotte":
return 183
if city == "Tampa":
return 220
if city == "Pittsburgh":
return 222
if city == "Los Angeles":
return 475
else:
return "Invalid Destination"

def rental_car_cost(days):
cost = days * 40
if days >= 7:
cost -= 50
elif days >= 3:
cost -= 20

def trip_cost(city, days):
return rental_car_cost(days)+plane_ride_cost(city)+hotel_cost(days)
print trip_cost(Tampa,10)


#2

If there's something subtle here then make sure that the code in your post is intact

(Need to be able to copy code from your post and run it and get the same thing to happen)


#3

I don't understand what you want me to do exactly. I am sure you are explaining what I did wrong to the best of your ability, but I do not comprehend.


#4

If you look at the code in your post, does it look like Python would run it? Copy it from your post, try. Does the same thing happen as for the code that you're trying to get to work? If not, then it isn't helping your question right. Because your question is about some code that's different from the code in your post.

At a glance, I don't see anything wrong. I could easily be missing something, especially if it's not something obvious. So I would need to run it, I would need to reproduce the issue that you describe. I can't do that if the code you're showing me doesn't reproduce what you describe.


#5

Héy Man, ^^
i can help you :slightly_smiling: !!
this is your code for solve this step :wink: !!
================================
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 False
def rental_car_cost(days):
amount = 40 * days
if days >= 7:
amount -= 50
elif days >= 3:
amount -= 20
return amount
print rental_car_cost
def trip_cost(city, days):
return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)
================================


#6

Thank you! I know people don't believe in copying or getting the answer right away but I do try to do it on my own. Such as watch videos on what I am stuck on with coding or look at some one else's code and figure out how bad mine is and what I did wrong. I do type the code instead of copying+pasting it.


#7

@javarunner58539 Cool ^^ !!


#8

And the reason I don't is that if you're not able to write it yourself then you've found something to learn (great) and most definitely shouldn't rush through it (missing the point)

It can definitely be difficult to know what skill or knowledge is missing and that leads to frustration - this is where it's a good idea to start asking questions, and questions asking about how the problem can be approached are way more rewarding. They're also rare, I'd like to think that those who do this end up asking way less questions.

It's like treating the symptoms vs treating the cause for the symptoms.


#9

@ionatan Exactlly ^^ !!


#10

A post was split to a new topic: 5. pull it together maximum recursion depth exceeded