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))
跟着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))
相关文章推荐
- Python应用科学计算和图表绘制
- python日志操作(loggin模块)
- python os模块文件目录
- [每日一课】 Python官方文档--- 函数进阶
- 美团多渠道打包方案详解,速度快到白驹过隙
- python微教程---第一季(第二集)----基础知识(让python运行起来)
- python获取页面元素的内容及长度
- 三、Python运算符与表达式
- 二、Python变量
- 一、Python的文件类型
- Python 内建函数_基础篇
- pandas操作积累
- Python Requests笔记
- Python import 功能_基础篇
- numpy判断数值类型、过滤出数值型数据
- python 读取线 的shp文件
- 浅谈python为什么不需要三目运算符和switch
- 利用python进行数据分析-数据规整化3
- python-logging模块详解
- 第6章 Python连接器的参数