Python 小练习 出差费用

来源:互联网 发布:微信可以打开淘宝地址 编辑:程序博客网 时间:2024/06/11 19:16


跟着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))

0 0