python作业

1   #### 用户登陆 #####

#!/usr/bin/env python
# coding:utf-8

'''
@author:liurong
@file:password.py
@contact:liurong@qq.com
@time:7/11/173:27 PM
@desc:
'''
print '''
        欢迎来到用户管理系统!
1) (L)ogin: 登陆
2) (C)reate:注册
3) (D)elete:删除用户
4) (V)iew:  查看用户
'''

import datetime
def create():
    newuser = raw_input("请输入注册用户名:")
    newpassword = raw_input("请设置用户密码:")
    dic[newuser]=newpassword
    print "用户建立成功"

def login():
    user = raw_input("请输入用户名:")
    password = raw_input("请输入密码:")
    time0 = datetime.datetime(2017, 7, 11, 12, 0)
    if user not in dic:
        print "不存在此用户,请重新输入"

    else:
        if dic[user] != password:
            print "密码错误,请重新登陆"
        else:

            time = datetime.datetime.now()
            if (time-time0).seconds <14400:
                print "你已经在4小时内登陆过"
            else:
                print '''
                                                    登陆成功
                                  '''
                time0=time
def delete():
    deleteuser=raw_input("请输入要删除的用户名:")
    deletepassword=raw_input("请输入密码:")
    if deleteuser not in dic:
        print "不存在此用户,请重新输入"
    else:
        if dic[deleteuser] != deletepassword:
            print "密码错误,请重新输入"
        else:
            dic.pop(deleteuser)
            print "删除成功"

def view():
    user = raw_input("请输入用户名:")
    password = raw_input("请输入密码:")
    if user not in dic:
        print "不存在此用户,请重新输入"

    else:
        if dic[user] != password:
            print "密码错误,请重新输入"
        else:
            print dic.keys()


dic = {"user1": "123", "user2": "456", "user3": "789"}
while True:
    choice = raw_input("请输入选项:")

    if choice == "L"or choice == "l":
        login()
    elif choice == "C"or choice == "c":
        create()
    elif choice == "D"or choice == "d":
        delete()
    elif choice == "V"or choice == "v":
        view()


2 #### 购物车 ####

#!/usr/bin/env python
# coding:utf-8

'''
@author:liurong
@file:gouwuche.py
@contact:liurong@qq.com
@time:7/11/173:44 PM
@desc:
'''
goods=(
    ["ipone10",18000],
    ["cup",20],
    ["bike",2000],
    ["book",100]
)
buy=[]
print '''
        程序操作
B:购买商品
Q:退出
'''
salary = input("请输入可用金额:")
while(True):
    choice=raw_input("请输入操作:")
    if choice=="Q" or choice=="q":
        exit()
    elif choice=="B"or choice=="b":
        print '''
            商品列表
        '''
        for k,v in enumerate(goods):
            print k,v

        num = input("请选择商品,输入商品编号可加入购物车(0|1|2|3):")


        if salary < goods[num][1]:
            print "金额不足"
        else:
            salary=salary-goods[num][1]
            print "%s 购买成功" % goods[num][0]
            buy.append(goods[num][0])
            print '''
                    消费单
            购买商品:%s
            消费金额:%d
            当前余额:%d
            ''' %(buy,goods[num][1],salary)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值