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 ...
随机推荐
- Simple Daemon Shell
PROPATH="/var/www/html/" PROGRAM="vertical" LOGNAME="/tmp/monitor.vertical. ...
- Windows Server 2008企业64位版防火墙添加端口的方法
原始地址:http://www.veryhuo.com/a/view/48280.html 什么是防火墙的入站规则和出站规则 简单的说 出站就是你访问外网 入站就是外网访问你 记得在两年前写过一篇教程 ...
- SQLServer 2012 可视化窗口中,设置“时间”默认值为“当前时间"
最近,需要在SQLServer 2012中,设置datetime的默认值为当前时间. 通过可视化窗口进行设置,而不是将getdate()函数写在sql语句中,也不是将‘2022-2-2 22:22:2 ...
- css3投影讲解、投影
迷茫了好一段时间,今天开始整理一下自己,同时也整理下新的知识. CSS3: 从头开始做起:现在在页面中用到最多的是图片/容器投影,文字投影: 接下来就总结一个投影问题: box-shadow:阴影类型 ...
- TensorFlow 深度学习笔记 TensorFlow实现与优化深度神经网络
转载请注明作者:梦里风林 Github工程地址:https://github.com/ahangchen/GDLnotes 欢迎star,有问题可以到Issue区讨论 官方教程地址 视频/字幕下载 全 ...
- Delphi在Webbrowser上绘制图像
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- Inno Setup 网页显示插件 webctrl (V2.1 版本)
原文 http://restools.hanzify.org/article.asp?id=90 Inno Setup网页显示插件 webctrl能够显示所有 IE 中能够显示的东西. 引用内容 ; ...
- 2014.8.15模拟赛【公主的工作】&&bzoj1046[HAOI2007]上升序列
bzoj题目是这样的 Description 对于一个给定的S={a1,a2,a3,…,an},若有P={ax1,ax2,ax3,…,axm},满足(x1 < x2 < … < xm ...
- poj 1573 Robot Motion_模拟
又是被自己的方向搞混了 题意:走出去和遇到之前走过的就输出. #include <cstdlib> #include <iostream> #include<cstdio ...
- Codeforces Round #258 (Div. 2/B)/Codeforces451B_Sort the Array
解题报告 http://blog.csdn.net/juncoder/article/details/38102391 对于给定的数组,取对数组中的一段进行翻转,问翻转后是否是递增有序的. 思路: 仅 ...