<p>我不知道我把事情搞砸了。我两天前刚开始使用Python,这是我的问题所在。你知道吗</p>
<p><strong>错误</strong></p>
<p><code>trip_cost('Pittsburgh', 4) raised an error: coercing to Unicode: need string or buffer, int found</code></p>
<p><strong>代码</strong></p>
<pre><code>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
else:
return 475
def rental_car_cost(days):
cost = days * 40
if days >= 7:
cost = cost - 50
elif days >= 3:
cost = cost - 20
return cost
def trip_cost(city, days):
city = raw_input("What city are you travelling to?")
days = raw_input("How many days are you staying?")
total_cost = hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days)
print total_cost
</code></pre>