关于python的问题,找零,帮忙找下错误,初学python
#-*-coding:cp936-*-defmain():j=input("输入价格:(元)")zz=(1-j)*100a1,a2=zhaolin(zz,50)b1,b2...
# -*- coding: cp936 -*-
def main():
j=input("输入价格:(元)")
zz=(1-j)*100
a1,a2=zhaolin(zz,50)
b1,b2=zhaolin(a2,20)
c1,c2=zhaolin(b2,10)
d1,d2=zhaolin(c2,5)
e1,e2=zhaolin(d2,2)
f1,f2=zhaolin(e2,1)
print a1,b1,c1,d1,e1,f1
def zhaolin(x,y):
z=x\y
w=x-x\y*y
return z,w
main()
问题是用 一元钱买东西,找钱,运行时图一错误 展开
def main():
j=input("输入价格:(元)")
zz=(1-j)*100
a1,a2=zhaolin(zz,50)
b1,b2=zhaolin(a2,20)
c1,c2=zhaolin(b2,10)
d1,d2=zhaolin(c2,5)
e1,e2=zhaolin(d2,2)
f1,f2=zhaolin(e2,1)
print a1,b1,c1,d1,e1,f1
def zhaolin(x,y):
z=x\y
w=x-x\y*y
return z,w
main()
问题是用 一元钱买东西,找钱,运行时图一错误 展开
3个回答
展开全部
没看懂你的需求,不过出错的原因是因为除号用错了,下面这样就行了
# -*- coding: cp936 -*-
def main():
j=input("输入价格:(元)")
zz=(1-j)*100
a1,a2=zhaolin(zz,50)
b1,b2=zhaolin(a2,20)
c1,c2=zhaolin(b2,10)
d1,d2=zhaolin(c2,5)
e1,e2=zhaolin(d2,2)
f1,f2=zhaolin(e2,1)
print a1,b1,c1,d1,e1,f1
def zhaolin(x,y):
z=x/y
w=x-x/y*y
return z,w
main()
修改了一下,应该满足了你的要求了。
# -*- coding: cp936 -*-
def main():
j=input("输入价格:(元)")
zz = 100 - j*100
zhaolin2(zz)
# a1,a2=zhaolin(zz,50)
# b1,b2=zhaolin(a2,20)
# c1,c2=zhaolin(b2,10)
# d1,d2=zhaolin(c2,5)
# e1,e2=zhaolin(d2,2)
# f1,f2=zhaolin(e2,1)
# print a1,b1,c1,d1,e1,f1
def zhaolin(x,y):
z=x/y
w=x-x/y*y
return z,w
def zhaolin2(x):
linqian_jiao = [50,20,10]
for i in linqian_jiao:
x_tmp = x/i
if x_tmp >= 1:
x_tmp = int(x_tmp)
x = x - i*x_tmp
jiao = i/10
print '找您'+ str(x_tmp) + '个' + str(jiao) + '角硬币;'
linqian_fen = [5,2,1]
for i in linqian_fen:
x_tmp = int(x//i)
if x_tmp >=1:
x_tmp = int(x_tmp)
x = x - i*x_tmp
x_tmp = int(x_tmp)
print '找您'+ str(x_tmp) + '个' + str(i) + '分硬币;'
main()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询