2015-05-10 152 views
-5

我試着使用鍵盤輸入來創建一個假的計算器,但是當我運行的代碼我得到:Python 3的打印功能

<function trip_cost at 0x01FF3348> 

我的代碼是:

city = input("What city will you vacation at?") 
days = input("How many days will you be staying there?") 
def hotel_cost(days): 
    return 140 * days 
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): 
    cost = 40 * days 
    return cost 

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

我怎樣才能得到它要退還它將花費的金額?

感謝

回答

1

如果你要調用的函數trip_cost並打印其結果是,你需要顯式調用它。而且您還需要傳遞其參數citydays參數。例如:

print(trip_cost(city, days)) 

你在做什麼只是打印函數對象本身,這是合法的,但不是很有用。

+0

好的,謝謝 – OceanS

+0

@OceanS如果這回答了你的問題,請點擊箭頭下方的勾號來接受它。 – EpsilonX

1

你是不是調用該函數,你還需要通過兩個參數:

print (trip_cost(city,days)) 

您還需要確保你定義了全市和天或直接值傳遞給函數。

+0

好的,謝謝 – OceanS

0

您必須使用打印功能中的有效參數調用函數trip_cost才能使其實際打印值。