Python作业day2购物车
流程图:
实现情况:
可自主注册,
登陆系统可购物,充值(暂未实现),查询余额。
撸了两天一夜的代码,不多说,直接上码,注释神马的后面再说
#!/usr/bin/env python
# -*- coding:utf-8 -*-
shopping_list = [
['Iphone 6s plus',5800],
['Lumia',3800],
['Charge',45],
['Data line',35],
['MI 5 PRO',2299],
['MX4',1999],
]
salary = 100000
total = 0
shop_list = [] while True:
welcome_1 = "欢迎使用XXX购物商城"
we_1 = welcome_1.center(30,'*')
print(we_1)
choice_1 = "1.注册 2.登陆 q.退出"
ch_1 = choice_1.center(32,'*')
exit_1 = "谢谢使用,欢迎下次光临"
ex_1 = exit_1.center(30,'*')
error_1 = "您输入的用户已存在,请重新输入"
e_1 = error_1.center(30,'-')
error_2 = "密码不能为空,请重新输入"
e_2 = error_2.center(30,'-')
error_3 = "您输入的密码太短,请重新输入"
e_3 = error_3.center(30,'-')
error_4 = "您的输入有误, 请重新输入"
e_4 = error_4.center(26,'*')
error_5 = " 您的账号已被锁定,请联系管理员 "
e_5 = error_5.center(12,'*')
print(ch_1 )
sr_1 = input("Please input:")
if sr_1 == '1':
while True:
with open('ming.txt','r')as r_1:
temp = r_1.readlines()
tlist = []
for tline in temp:
tline = tline.strip().split(':')
tlist.append(tline[0])
useradd = input("Please create user:")
success_1 = "成功创建用户:%s" %(useradd)
if useradd in tlist:
print(e_1 )
elif useradd == "exit":
break
else:
passwd = input("Please create a password(Letters and numbers):")
length = len(passwd)
if length == 0 :
print(e_2)
elif length > 7:
with open('ming.txt','a')as r_3:
w_1 = '%s:%s:0\n' %(useradd,passwd)
r_3.write(w_1)
s_1 = success_1.center(30,'-')
print(s_1)
break
else:
print(e_3) elif sr_1 == '2':
flag = False
while True:
username = input("Please enter a user name:")
l = open('lock.txt','r')
for lline in l.readlines():
lline = lline.strip()
if username == lline:
print("账号被锁")
flag = True
l.close()
break
if flag == True:
break u = open('ming.txt','r')
for uline in u.readlines():
user,password,mony = uline.strip().split(':') if username == user:
i = 0
while i < 3:
passwd = input('Please enter a password:')
i +=1
if passwd == password:
print('欢迎%s登陆在线购物平台' % username)
flag = True
u.close()
break
else:
if i >= 3:
with open('lock.txt','a') as l_2:
l_2.write(username + '\n')
l.close()
exit("试了太多次,将被锁定,请联系管理员")
print('密码输入错误,还有%d次机会' % (3 - i))
break
else:
print("用户输入错误,请重新输入") while True:
print("1.购物 2.查看购物车 3.查询余额 4.充值 b.返回登陆 q.退出")
print("------------------------------------------------")
choice_2 = input("输入序号:")
flag_1 = False
while True:
if choice_2 == "":
while True:
for index,g in enumerate(shopping_list):
print(index,g[0],g[1])
print("-------------------------")
print("c.查看购物车 b.返回 q.退出")
print("-------------------------")
choice = input("键入数字选择商品:").strip()
if choice.isdigit():
choice = int(choice)
p_price = shopping_list[choice][1]
if p_price < salary:
shop_list.append(shopping_list[choice])
total += p_price
salary -= p_price
print("-------------------------")
print("您购买了%s,余额为%s"%(shopping_list[choice][0],salary))
print("-------------------------")
else:
print("-------------------------")
print("您的余额不足")
print("-------------------------")
elif choice == "c":
while True:
print("----------购物车----------")
for k,v in enumerate(shop_list):
print(k,v[0],v[1])
print("已消费金额为:%s"%total)
print("您的可用余额:%s"%salary)
print("-------------------------")
print("d.删除商品 b.返回购物 q.结算退出")
print("-------------------------")
choice_1 = input("请键入字母选择功能:")
print("-------------------------")
if choice_1 == "d":
print("-------------------------")
print("输入数字为删除商品,输入字母b为返回购物车")
print("-------------------------")
while True:
choice_2 = input("请选择:")
if choice_2.isdigit():
choice_2 = int(choice_2)
d_price = shop_list[choice_2][1]
shop_list.remove(shop_list[choice_2])
total -= d_price
salary += d_price
print("-------------------------")
print("商品%s删除成功,可用余额为:%s"%(shop_list[choice_2][0],salary))
print("-------------------------")
elif choice_2 == "b":
break
elif choice_1 == "b":
flag = True
break
else:
print("----------购物清单----------")
for k,v in enumerate(shop_list):
print(k,v[0],v[1])
print("总消费金额为:%s"%total)
print("您的可用余额:%s"%salary)
print("--------欢迎下次再来-------")
exit(0)
elif choice == "b":
break
elif choice == "q":
print("----------购物清单----------")
for k,v in enumerate(shop_list):
print(k,v[0],v[1])
print("总消费金额为:%s"%total)
print("您的可用余额:%s"%salary)
print("--------欢迎下次再来--------")
exit(0)
else:
print("-------------------------")
print("您的输入有误,请重新输入")
print("-------------------------")
if flag == True:
break
elif choice_2 == "":
print("----------购物车----------")
for k,v in enumerate(shop_list):
print(k,v[0],v[1])
print("已消费金额为:%s"%total)
print("您的可用余额:%s"%salary) print("-------------------------")
break
elif choice_2 == "":
with open('ming.txt','r')as m_1:
mony_1 = m_1.readlines()
for mline in mony_1:
(user,password,mony) = mline.strip().split(':')
print(salary)
flag_1 = True
break
break elif choice_2 == "":
z = 0
while z < 1:
chongzhi = int(input("输入金额:"))
passwd_1 = input("请输入密码:")
m = open('ming.txt','r+')
m_2 = m.readlines() for mline in m_2:
(user,password,mony) = mline.strip().split(':') if passwd_1 == password:
mony_2 = (chongzhi + int(mony)) w_2 = '%s:%s:%s\n' %(username,password,mony_2)
m.write(w_2)
print("充值成功")
print(mony)
flag = True
break
continue
break
if flag == True:
break elif choice_2 == "b":
flag = True
break elif choice_2 == "q":
exit(ex_1)
else:
print(e_4)
break
break
if flag == True:
break
break
elif sr_1 == 'q':
exit(ex_1)
else:
print(e_4)
print(' ')
购物车
Python作业day2购物车的更多相关文章
- (转)Python作业day2购物车
Python作业day2购物车 原文:https://www.cnblogs.com/spykids/p/5163108.html 流程图: 实现情况: 可自主注册, 登陆系统可购物,充值(暂未实现) ...
- Python作业之购物车
作业之购物车 购物车的要求如下: 输入总金额 选择购买的商品,金额足够时,把选择的商品添加到购物车,金额不足时,进行提示,商品将不会添加到购物车 随时可以退出程序,同时输出已购买的商品 具体代码如下: ...
- python作业:购物车(第二周)
一.作业需求: 1.启动程序后,输入用户名密码后,如果是第一次登录,让用户输入工资,然后打印商品列表 2.允许用户根据商品编号购买商品 3.用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒 4 ...
- python作业ATM(第五周)
作业需求: 额度 15000或自定义. 实现购物商城,买东西加入 购物车,调用信用卡接口结账. 可以提现,手续费5%. 支持多账户登录. 支持账户间转账. 记录每月日常消费流水. 提供还款接口. AT ...
- python s12 day2
python s12 day2 入门知识拾遗 http://www.cnblogs.com/wupeiqi/articles/4906230.html 基本数据类型 注:查看对象相关成员 var, ...
- python练习_购物车(简版)
python练习_购物车(简版) 需求: 写一个python购物车可以输入用户初始化金额 可以打印商品,且用户输入编号,即可购买商品 购物时计算用户余额,是否可以购买物品 退出结算时打印购物小票 以下 ...
- Python作业第一课
零基础开始学习,最近周边的同学们都在学习,我也来试试,嘿嘿,都写下来,下次不记得了还能来看看~~ Python作业第一课1)登陆,三次输入锁定,下次不允许登陆2)设计一个三级菜单,菜单内容可自行定义, ...
- Python作业-选课系统
目录 Python作业-选课系统 days6作业-选课系统: 1. 程序说明 2. 思路和程序限制 3. 选课系统程序目录结构 4. 测试帐户说明 5. 程序测试过程 title: Python作业- ...
- python基础day2作业:购物车
#功能:1.可注册账号2.登录买家账号3.可查询编辑购物车里商品4.可以余额充值5.可提示余额不足6.购物车结算 #使用:1.第一次使用先注册账号填写账号金额2.账号金额信息保存在buyer_acco ...
随机推荐
- 开启MongoDB 脚本和设置window自启
wwchen: D: cd D:\Program Files\MongoDB\Server\3.2\bin mongod --dbpath=D:\mongodb\db----------------- ...
- 一个纯CSS DIV天气动画图标【转扒的】
<p> </p> <style><!-- /* SUNNY */ .sunny { -webkit-animation: sunny 15s linear i ...
- 学php之翻译wordpress(1)
单看文件结构,wordpress分了3个文件夹 wp-admin,wp-content,wp-includes 和零散的一堆php,暂时不清楚各自的分工 入口文件是index.php <?php ...
- 微信OPENID授权方法
今天搞了下微信授权, 总结了下微信的授权规则与步骤 先来几个关键字 Openid 微信ip(属于唯一指向公众号的id) redirect_uri 授权回调地址 State 回调地址带参数 Appi ...
- 1003 Crashing Balloon
考察DFS的应用,判断两个数的因子. #include <stdio.h> int f1,f2; void DFS(int m,int n,int k){ ){ f2=; ) f1=; } ...
- Nginx 配置指令的执行顺序(十)
运行在 post-rewrite 阶段之后的是所谓的 preaccess 阶段.该阶段在 access 阶段之前执行,故名preaccess. 标准模块 ngx_limit_req 和 ngx_lim ...
- DM368启动串口打印分析
DM36x initialization passed! TI UBL Version: 1.50 Booting Catalog Boot Loader //启动目 ...
- Table XXX is marked as crashed and should be repaired问题
数据表出错了,查询数据获取不到了. 尝试一 重启mysql service mysqld restart 没用,重启并没有把表修复掉 尝试二 check table vicidial_list;rep ...
- Jenkins的安全控制
在默认配置下,Jenkins是没有安全检查的.任何人都可以以匿名用户身份进入Jenkins,设置Jenkins和Job,执行build操作.但是,Jenkins在大多数应用中,尤其是暴露在互联网的应用 ...
- 灵活使用getconf命令来获取系统信息
http://blog.chinaunix.net/uid-23105261-id-109513.html 灵活使用getconf命令来获取系统信息 我们时常需要查询系统相关的信息,比如页面大小,整数 ...