《面试》 --阿里巴巴数据分析岗面试编程题解析
来源:互联网 发布:哥伦比亚大学 知乎 编辑:程序博客网 时间:2024/06/15 08:45
昨天做阿里非研发岗编程题,虽不是很难,但还是因为个人原因调试失败,特此今日复盘,希望能帮助大家提高。
第一题
选择出行方式,ofo是每1.5公里1元,不足1.5公里的按1.5计算
永安行是使用时间,每分钟0.2元,使用时间不足1分钟按1分钟算。
hellobike是不足2km 1元,不足4km 3元,不足8公里,5元,超过8km 8元,选择合适的出行方式
def bike_plan(distance, speed): # 计算出三种方式的花费 ofo = distance/1.5 if ofo > int(ofo): ofo = float(int(ofo)+1) yongan_1 = distance/speed if yongan_1 > int(yongan_1): yongan_1 = float(int(yongan_1)+1) yongan = 0.2*yongan_1 if distance<= 2: hellobike = 1.0 elif distance <= 4: hellobike = 3.0 elif distance <= 8: hellobike = 5.0 else: hellobike = 8.0 # 将花费放置在h中 h = [] h.append(ofo) h.append(yongan) h.append(hellobike) print h # 找出所有值和最小值相同的坐标,放入h1中 h1 = [] for i in range(3): if h[i] == min(h): h1.append(h.index(min(h),i)) print h1 **# index(self) # index(...) # L.index(value, [start, [stop]]) -> integer -- return first index of value. # Raises ValueError if the value is not present. # 当值不存在的时候,返回的ValueError ,汗当时没考虑到这个问题啊!** # 通过坐标找到相对应的骑行方式,放置在h3中,方便最后输出 h2 = ['ofo','永安行','hellobike'] h3 = [] for i in h1: h3.append(h2[i]) print '骑行距离'+str(distance)+'(千米),匀速骑行速度'+str(speed)+'(千米/分钟)最省钱方案:' if len(h3) == 1: return h3[0] + str(min(h)) +'(元)' if len(h3) == 2: return h3[0] + str(min(h)) +'(元)和'+h3[1] + str(min(h)) +'(元)' if len(h3) == 3: return h3[0] + str(min(h)) +'(元)和'+h3[1] + str(min(h)) +'(元)'+h3[2]+ str(min(h)) +'(元)'_distance = float(raw_input())_speed = float(raw_input())res = bike_plan(_distance, _speed)print res + "\n"
阅读全文
0 0
- 《面试》 --阿里巴巴数据分析岗面试编程题解析
- 2014阿里巴巴数据分析师面试
- 2015阿里巴巴数据分析师实习生招聘面试经验
- 阿里巴巴数据研发工程师面试
- 阿里巴巴面试
- 阿里巴巴面试
- 阿里巴巴面试
- 面试 阿里巴巴
- 阿里巴巴Java岗面试经验
- 面试1题解析
- 数据分析师面试
- 阿里巴巴面试与面试技巧
- [Java--面试]--阿里巴巴面试2016
- 面试数学趣题解析
- 程序员面试逻辑题解析
- 公务员面试真题解析
- 公务员面试真题解析
- 2014阿里巴巴面试总结(测试岗)
- FFT学习笔记<理论篇>
- 字符设备驱动之register_chrdev_region()系列
- 2.1 类和对象
- 字符数组的赋值
- 测试流程及规范
- 《面试》 --阿里巴巴数据分析岗面试编程题解析
- spark所支持的文件格式
- Centos 6,7安装用yum命令 mysql 5.7
- shell常用代码
- css中position的详细介绍
- 【题解】2006 能量项链(P1063)
- java jar的解释
- 改写ui-grid headerCellTemplate
- 【PHP】深入理解PHP的session。