python简易自动售货系统,Python代码饮料自动售货机
这篇文章主要为大家详细介绍了大蟒实现自动售货机,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了大蟒实现自动售货机的具体代码,供大家参考,具体内容如下
自动售货机代码
而True:
n=输入(请选择操作:)
如果n==r:
l=输入(请输入货物数量:)
v=l.split(-)
numA1=int(v[0])
numA2=int(v[1])
numA3=int(v[2])
numA4=int(v[3])
numA5=int(v[4])
numA6=int(v[5])
t=输入(请输入硬币数量:)
u=t.split(-)
yiyuan=int(u[0])
梁源=int(u[1])
wuyuan=int(u[2])
shiyuan=int(u[3])
打印(“s 001:初始化成功")
elif n==q:
打印(会员管理。中心(50, * )
打印("")
操作目录
0-货物剩余量
1-钱盒)
而True:
c=输入()
如果c==0:
print( A1 % d A2 % d A3 % d A4 % d A5 % d A6 % d %(numa 1,numA2,numA3,numA4,numA5,numA6))
elif c==1:
打印( 1元硬币数=% d 2元硬币数=% d 5元硬币数=%d 10元硬币数=% d“%(一元、两元、五元、十元))
elif n==p:
counname=input(请选择商品:)
if counname==1:
如果numA1=0:
打印(“E007:The商品售完")
else:
m=输入(请输入现金:)
如果m==1:
打印( S003:Buy购买购买成功,余额=1 )
打印(“E009:Work工作工作失败")
numA1-=1
yiyuan=1
elif m==2:
打印( S003:Buy购买购买成功,余额=1 )
numA1-=1
梁园=1
一元-=1
打印(找您一元)
elif m==5:
如果一元*1两元*25:
打印( e 00:更改零钱不够,支付失败)
else:
打印)工资支付成功,余额=1 )
打印( S003:Buy购买购买成功,余额=1 )
numA1-=1
婺源=1
梁园-=2
打印(找您四元)
elif m==10:
如果一元*1两元*210:
打印( e 00:更改零钱不够,支付失败)
else:
打印)工资支付成功,余额=1 )
打印( S003:Buy购买购买成功,余额=1 )
十元=1
婺源-=1
梁园-=2
打印(找您9元)
e
lse:
print(E002:Denomination error)
elif counname == 2:
if numA2 <= 0:
print(E007:The goods sold out)
else:
m=input(请输入现金:)
if m == 1:
print(E008:Lack of balance)
elif m == 2:
print(S003:Buy success,balance=1)
print(E009:Work failure)
numA2 -= 1
liangyuan += 1
elif m == 5:
if yiyuan * 1 + liangyuan * 2 < 5:
print(E003:Change is not enough,pay fail)
else:
print(S002:Pay success,balance=2)
print(S003:Buy success,balance=1)
wuyuan+=1
yiyuan-=1
liangyuan-=1
print(找您三元)
elif m == 10:
if yiyuan * 1 + liangyuan * 2 < 10:
print(E003:Change is not enough,pay fail)
else:
print(S002:Pay success,balance=2)
print(S003:Buy success,balance=1)
numA2-=1
shiyuan+=1
wuyuan-=1
yiyuan-=1
liangyuan-=2
print(找您8元)
else:
print(E002:Denomination error)
elif counname == 3:
if numA3 <= 0:
print(E007:The goods sold out)
else:
m=input(请输入现金:)
if m == 1:
print(E008:Lack of balance)
elif m == 2:
print(E008:Lack of balance)
elif m == 5:
if yiyuan * 1 + liangyuan * 2 < 5:
print(E003:Change is not enough,pay fail)
else:
print(S002:Pay success,balance=3)
print(S003:Buy success,balance=1)
numA3-=1
wuyuan += 1
liangyuan -= 1
print(找您三元)
elif m == 10:
if yiyuan * 1 + liangyuan * 2 < 10:
print(E003:Change is not enough,pay fail)
else:
print(S002:Pay success,balance=3)
print(S003:Buy success,balance=1)
numA3 -= 1
shiyuan += 1
wuyuan -= 1
liangyuan -= 1
print(找您7元)
else:
print(E002:Denomination error)
elif counname == 4:
if numA4 <= 0:
print(E007:The goods sold out)
else:
m=input(请输入现金:)
if m == 1:
print(E008:Lack of balance)
elif m == 2:
print(E008:Lack of balance)
elif m == 5:
if yiyuan * 1 + liangyuan * 2 < 5:
print(E003:Change is not enough,pay fail)
else:
print(S002:Pay success,balance=4)
print(S003:Buy success,balance=1)
numA4 -= 1
wuyuan += 1
yiyuan -= 1
print(找您1元)
elif m == 10:
if yiyuan * 1 + liangyuan * 2 < 10:
print(E003:Change is not enough,pay fail)
else:
print(S002:Pay success,balance=4)
print(S003:Buy success,balance=1)
numA4 -= 1
shiyuan += 1
wuyuan -= 1
yiyuan -= 1
print(找您6元)
else:
print(E002:Denomination error)
elif counname == 5:
if numA5 <= 0:
print(E007:The goods sold out)
else:
m=input(请输入现金:)
if m == 1:
print(E008:Lack of balance)
elif m == 2:
print(E008:Lack of balance)
elif m == 5:
print(E008:Lack of balance)
elif m == 10:
if yiyuan * 1 + liangyuan * 2 < 10:
print(E003:Change is not enough,pay fail)
else:
print(S002:Pay success,balance=6)
print(S003:Buy success,balance=1)
numA5 -= 1
shiyuan += 1
liangyuan-=2
print(找您4元)
else:
print(E002:Denomination error)
elif counname == 6:
if numA6 <= 0:
print(E007:The goods sold out)
else:
m=input(请输入现金:)
if m == 1:
print(E008:Lack of balance)
elif m == 2:
print(E008:Lack of balance)
elif m == 5:
print(S003:Buy success,balance=1)
print(E009:Work failure)
numA6 -= 1
wuyuan+=1
elif m == 10:
if yiyuan * 1 + liangyuan * 2 < 10:
print(E003:Change is not enough,pay fail)
else:
print(S002:Pay success,balance=5)
print(S003:Buy success,balance=1)
numA6 -= 1
shiyuan += 1
wuyuan -= 1
print(找您5元)
else:
print(E006:Goods does not exist)
else:
print(操作无效)
解释说明:钱币盒内只有,一元,两元,五元,十元的硬币;顾客也只能投入这些,钱币盒内一元和两元的总面额必须大于顾客给的面额,顾客一次只能投一次钱并买一件商品,但可以多次投入多次购买。货物数量和钱币数量由管理员初始化设定,管理员也可以查看钱币及货物数量,但查看完毕必须退出。如果投入钱币恰好等于商品价格,则购买成功并提示余额为0,工作失败,意味后续无法购买。
r——–初始化,必须初始化后才能执行程序
q——-管理员查看钱盒和货物信息
p——-顾客购买商品及付款及退钱
如图有:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持盛行IT软件开发工作室。
郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。