2017-03-21 12 views
-4

これは、旅行のコストを返すPython関数です。私は何が間違っているのか理解できません。何も呼ばれません。何か不足していますか?Python - 関数を呼び出す

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 

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

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

print trip_cost("Charlotte", 6) 
+7

あなたはインデントの問題を抱えているを追加しました。最後の行をインデントしてはいけません。 –

+0

それはそれを修正しません.. – Merialc

+4

結果を印刷するのを忘れているかもしれません。 'print(trip_cost())'を試してください –

答えて

0

書き込み

print trip_cost("Charlotte", 6) 

あなたは「trip_cost」関数を呼び出し、戻り値を取得しますが、戻り値を何もしていませんされています。出力用プリント

0

は、次のコードは、私の作品と1243年を返します表示するには:

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 

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

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

print(trip_cost("Charlotte", 6)) 

私はいくつかの役に立たないインデントを削除し、「印刷」

関連する問題