python简单的购物系统
2024-10-01 11:46:18
#coding = utf-8
#2016-11-19
#我的工资是存在文件中的,执行后会判断是否存过工资,如果存过无需输入,直接购物,没存过需要输入工资
#wages.txt是存工资的文件
import os product_list = [
['iphone6', 5888],
['联想笔记本', 8000],
['iphone7', 6888], ]
shop_car = []
if os.path.getsize ('wages.txt'): # 判断是否写入工资
money = open ('wages.txt', 'r', encoding='utf-8')
your_money = money.readline ()
money.close () while True:
for item,p in enumerate (product_list): print (item, p[0], p[1]) user_choice = input ('请输入要购买的商品编号,按q退出:')
if user_choice.isdigit ():
user_choice = int (user_choice)
p_price = product_list[user_choice][1]
your_money = int(your_money)
if p_price < your_money:
shop_car.append(product_list[user_choice]) your_money -= p_price
with open ('wages.txt', 'w', encoding='utf-8') as m:
m.write(str(your_money))
print('加入购物车,剩余%d'%your_money)
else:
print('工资不够,努力赚钱')
elif user_choice == 'q':
for k,v in enumerate(shop_car):
print(k,v)
print('剩余钱数%d'%your_money)
exit()
else:
print('参数不正确,请重新选择')
else:
your_money = input('请输入你的工资')
if your_money.isdigit:
your_money = int (your_money)
with open ('wages.txt', 'w', encoding='utf-8') as money:
money.write (str (your_money))
while True:
for item, p in enumerate (product_list): print (item, p[0], p[1]) user_choice = input ('请输入要购买的商品编号,按q退出:')
if user_choice.isdigit ():
user_choice = int (user_choice)
p_price = product_list[user_choice][1]
if p_price < int(your_money):
shop_car.append (product_list[user_choice])
your_money -= p_price
with open ('wages.txt', 'w', encoding='utf-8') as m:
m.write (str (your_money))
print ('加入购物车,剩余%d' % your_money)
else:
print ('工资不够,努力赚钱吧小伙')
elif user_choice == 'q':
for k, v in enumerate (shop_car):
print (k, v)
print ('剩余钱数%d' % your_money)
exit ()
else:
print ('参数不正确,请重新选择')
else:
exit ('您的工资不合法:')
最新文章
- [node.js 学习]1.start a simple server
- 【加精】手机话费充值API接口(PHP版)
- CoreGraphics-线段常见属性及渲染模式介绍
- mac下剪切文件或文件夹
- 2016年11月19日--连接查询,变量、if else、while
- 高级iOS面试题
- 获取IplImage 数据并打印
- 精妙SQL语句 基础
- Websocket协议之php实现
- POJ1734 - Sightseeing trip
- 设计模式14---设计模式之命令模式(Command)(行为型)
- NET Core控制反转(IoC)
- MI &; CI
- java对象序列化、反序列化
- centos7之zabbix的web检测
- (81)Wangdao.com第十六天_JavaScript 严格模式
- C博客作业06--结构体&;文件
- 非web环境的注解配置的spring项目应用(non-web, Spring-data-jpa, JavaConfig, Java Application, Maven, AnnotationConfigApplicationContext)
- ecshop验证码图片无法显示终极解决办法
- ORACLE rollup函数