您的位置:首页 > 编程语言 > Python开发

Python 小练习 出差费用

2016-06-17 14:30 471 查看

跟着Codecademy 上面做个小练习

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):      

    cost = days*40

    if days>=7:

        cost -=50        #租车超过7天有折扣

    elif days>=3:     

        cost -=20        #租车超过3天有折扣

    return cost

    

def trip_cost(city,days,spending_money):        #多出一项spending_money ,额外费用

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

   

print (trip_cost('Los Angeles',5,600))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: