0
def hotel_cost():
    nights = input("how many days?")
    return 140 * nights

def plane_ride_cost():
    city = input("which city? Charlotte, Tampa, Pittsburgh or Los Angeles?")
    if city == "Charlotte":
        return 183
    elif city == "Tampa":
        return 220
    elif city == "Pittsburgh":
        return 222
    elif city == "Los Angeles":
        return 475


def rental_car_cost():
    days = input("how many days for renting a car?")
    pro_day = days * 40
    if days >= 7:
        return pro_day - 50
    elif days >=3:
        return pro_day - 20
    else:
        return pro_day

def trip_cost():
    return nights + city + pro_day + spending_money

print trip_cost(hotel_cost(),plane_ride_cost(),rental_car_cost()+  spending_money)

hi guys, can someone help me with this piece of code? i learned it on codeacademy and modified , want to make it user friendly but after running code i can choose days and after city name and after error. i am very noob in python , appreciate any kind of advice , thanks

elchinsolo
  • 90
  • 9
  • For a start, indent you code that's part of a function body. – Jacques de Hooge Apr 01 '16 at 18:19
  • 1
    My first advice is to read the error and try to guess what it is telling you. My second advice is to put the error with the whole traceback into your question. Without the error, it's hard to tell what you are doing wrong. – zondo Apr 01 '16 at 18:31

3 Answers3

2

Use

raw_input("which city? Charlotte, Tampa, Pittsburgh or Los Angeles? ")

instead of

input("which city? Charlotte, Tampa, Pittsburgh or Los Angeles? ").

Check this link NameError

Community
  • 1
  • 1
formatkaka
  • 1,278
  • 3
  • 13
  • 27
1

Check this out.You were missing spending money variable.I make a function for this,you can in-cooperate your logic in it.Also where your comparing an str object with int in rental_car_cost.Make sure to cast it first or compare it with a string type object.

def hotel_cost():
    nights = int(raw_input("how many days?"))
    return 140 * nights

def plane_ride_cost():
    city = raw_input("which city? Charlotte, Tampa, Pittsburgh or Los Angeles?")
    if city == "Charlotte":
        return 183
    elif city == "Tampa":
        return 220
    elif city == "Pittsburgh":
        return 222
    elif city == "Los Angeles":
        return 475


def rental_car_cost():
    days = int(raw_input("how many days for renting a car?"))
    pro_day = days * 40
    if days >= 7:
        return pro_day - 50
    elif days >=3:
        return pro_day - 20
    else:
        return pro_day

def spending_money():
    money_spent = int(raw_input("how much money will you spend there?"))
    return money_spent


def trip_cost():
    return hotel_cost() + plane_ride_cost() + rental_car_cost() + spending_money()


print trip_cost()
Randhawa
  • 614
  • 1
  • 6
  • 15
0

First you need to correctly indent your code.

Second, change input() to raw_input():

def plane_ride_cost():
    city = raw_input("which city? Charlotte, Tampa, Pittsburgh or Los Angeles?")

And

def rental_car_cost():
    days = raw_input("how many days for renting a car?")

Third, you need to type cast the String input to an int here:

def rental_car_cost():
    days = raw_input("how many days for renting a car?")
    pro_day = int(days) * 40

Your trip_cost() function is doing nothing. You don't have any variables for nights, city, pro_day, or spending_money. Move your print() inside the function.

def trip_cost():
    return nights + city + pro_day + spending_money

There are several ways to change this. You can move the print() thats at the end of your file inside the function and remove the return that's currently there, you could remove the print() and change your return to

return hotel_cost(), plane_ride_cost(), rental_car_cost() + spending_money

And then add a print(trip_cost()) to the end of your file. The choice is up to you.

Aaron
  • 992
  • 3
  • 15
  • 33
  • thanks Aaron i already managed it to work , but thanks for time you spent trying to help, i appreciate all kind of help ) – elchinsolo Apr 01 '16 at 18:43