python获取用户输入中文_获取函数的用户输入

平等问题:

提议

把它看作是改进代码的一部分。我想是的,它没有回答你的问题。在

我不知道代码学院对这个练习有什么建议,但下面是一些更简单、更干净的方法:print "this code calculates the total price of a trip, using 4 functions"

def hotel_cost(nights):

return 140 * nights

def plane_ride_cost(city):

#So you can create dict and put for each city

#Key - name of city

#value - cost

CITY_COST = {

"Charlotte": 183,

"Pittsburgh" : 222,

"Los Angeles" : 475,

"Tampa": "220"

}

#Method from dict

#if city doesn't exists it'll return False

#The second param is default return if doesn't exist key into dict

#you can change if do you want

return CITY_COST.get(city, False)

def rental_car_cost(days):

cost = days * 40

if (days >= 7):

cost -= 50

elif(days >=3 ):

cost -=20

return cost

def trip_cost(city,days,spending_money):

return rental_car_cost(days)+hotel_cost(days)+ plane_ride_cost(city)+spending_money

city= raw_input("enter city name")

days= raw_input("enter number of days staying")

spending_money= raw_input("enter spendig money")

print trip_cost(city,days, spending_money)

关于Dict的文档

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值