python作业(7.8 —— 7.9)
来源:互联网 发布:minecraft0.15js 编辑:程序博客网 时间:2024/05/22 10:34
8.登陆系统
import time
1). Creat :
2). Login :
3). Delete :
4). View :
登陆时判断本次登陆与上次登陆时间的差,如果time<4h,显示,你已经登陆在4小时前。
源代码:
#!/usr/bin/env python# coding:utf-8__author__ = "lvah"import time'''@author:fairy@file:8.py@time:7/10/1711:11 PM@DESC;'''hour = 4 * 60 * 60USER = {}def creat(): name1 = raw_input('new username:') if name1 not in USER.keys(): pass1 = raw_input('new passwprd:') USER[name1] = [pass1,0] else: print 'the username is existed,please give me a new name!' creat()def login(): if USER.keys() == 0: print 'no users exist,please create user' else: user_in = raw_input('username:') pass_in = raw_input('password:') d1 = time.time() if USER[user_in][1] == 0: if user_in in USER.keys() and pass_in == USER[user_in][0]: USER[user_in][1] = d1 print 'welcome to user system!' else: print 'error username or password!' else: if user_in in USER.keys() and pass_in == USER[user_in][0]: if d1 - USER[user_in][1] >= hour: print 'wlecome to user system!' else: d2 = (hour - (d1 - USER[user_in][1])) / 60 print 'you have been login in within 4 hours,please login after %d minutes' % d2 else: print 'error username or password!'def delete(): user1 = raw_input('username:') USER.pop(user1) print 'delete user successful'def view(): print USER.keys()def main(): cho = 'Enter your choice:' print ''' you can input: creare(c) login(l) delete(d) view(v) ''' while True: pro = raw_input(cho).lower() if pro == 'c': creat() elif pro == 'l': login() elif pro == 'd': delete() elif pro == 'v': view() else: print 'error:you can input c l d v'main()
测试:
12.购物车程序需求:
1)启动程序后,让用户输入公子,然后打印商品列表;
2)允许用户根据商品编号购买商品;
3)用户选择商品后,检测余额是否足够,够就直接扣款,不够就提醒;
4)可随时退出,退出时打印已购买的商品和余额;
your salary:
1 ipthon 5800
2 book 100
3 bike 200
>>>:1
added [ipthon] to your shopping
>>>:3
added [bike] to your shopping
>>>:q
have bought below:
#!/usr/bin/env python# coding:utf-8_author_ = "lvah"'''@author:fairy@file:homework_shopping.py@contact:xiaojun0118@foxmail.com@time:7/9/1711:17 AM@DESC;'''shopinfo = [ ['Iphon', 1000], ['book', 200], ['fentiao', 3500]]BUY =[]def buy(): a = input('请输入工资:') print '商品列表:' for num, shanping in enumerate(shopinfo): print num, shanping[0],shanping[1] num1 = input('请输入商品编号:') if a < shopinfo[num1][1]: print '余额不足' else: a1 = a - shopinfo[num1][1] BUY.append(shopinfo[num1][0]) print '余额:%d\n%s 购买成功' % (a1,shopinfo[num1][1])def main(): print '''欢迎进入购物车系统你可以:购买(B)退出(Q) ''' pro = raw_input('请输入选择:').lower() if pro == 'q': print '退出系统' elif pro == 'b': buy() else: print '你可以输入B , Q'main()
map/reduce练习题
(1)利用map()函数,把用户输入的不规范英文名字,变为首字母大写,其他小写的规范名字。输入:[‘adam’,’LISA’,’barT’],输出:[‘Adam’,’Lisa’,’Bart’]。
#!/usr/bin/env python#coding:utf-8__author__ = "lvah"'''@author:fairy@file:map.py@time:7/11/179:12 PM@DESC;'''def f(li): return li.title()print map(f,['adad','ASE','adaRR'])
测试:
(2)Python提供的sum()函数可以接受一个list并求和,请编写一个prod()函数,可以接受一个list并利用reduce()求积
#!/usr/bin/env python# coding:utf-8__author__ = "lvah"'''@author:fairy@file:reduce.py@time:7/11/179:24 PM@DESC;'''def f(x, y): return x * ydef prod(li): return reduce(f, li)print prod([3,5,4,7])
测试:
阅读全文
0 0
- python作业(7.8 —— 7.9)
- python作业7.8
- Python作业——day01_流程图
- 程序设计入门—Python 第一周作业
- python作业(面向对象)
- day10————python作业socket
- Python程序设计入门——第五周作业
- 机器学习基石—作业2(16-20题Python实现)
- 程序设计入门—Python之第二周作业
- python 作业
- Python作业
- python作业
- python作业
- Python作业
- python作业
- Python 作业
- Python 正则表达式(2)作业
- 作业:C++作业2—项目4
- 个人感悟
- 常量池、栈、堆的比较(慢慢消化)
- shord_ptr
- C语言学习中整理的知识
- Android进阶之路--启动模式
- python作业(7.8 —— 7.9)
- 关于变量说明
- Android_手势 滑动图片
- 【dp】51nod 1270 数组的最大代价
- java中String new和直接赋值的区别(空了还要补充)
- 4. Median of Two Sorted Arrays
- 关于MongoDb分片
- hash算法
- 欢迎使用CSDN-markdown编辑器