2017-09-16 125 views
0
num = input ("Please enter an amount in euros:") 
x = int (num) 
print (x) 
a = x // 500 # The operations are performed to find how many bills of each heat there is and its residue. 
x = x% 500 
if not a == 0: # Condition for the value of agreement only in the result of the residue in case none exists. 
b = x // 200 
x = x% 200 
else: b = x // 200 
yes no b == 0: 
c = x // 100 
x = x% 100 
else: c = x // 100 
if not c == 0: 
d = x // 50 
x = x% 50 
else: d = x // 50 
if not d == 0: 
e = x // 20 
x = x% 20 
else: e = x // 20 
if it is not e == 0: 
f = x/10 
x = x% 10 
else: f = x // 10 
if not f == 0: 
g = x // 5 
x = x% 5 
else: g = x // 5 # I make several conditions that allow me 
if not g == 0: #Evaluate the results of each operation 
h = x // 2 # immediately above. 
x = x% 2 
else: h = x // 2 
if not h == 0: 
i = x // 1 
x = x% 1 
else: i = x // 1 

print ("There", a, "500 euro banknote (s)") 
print ("There", b, "ticket (s) of 200 euros") 
print ("There", c, "ticket (s) of 100 euros") 
print ("There", d, "50 euro banknote (s)") # printout of results 
print ("There", and, "ticket (s) of 20 euros") 
print ("There", f, "ticket (s) of 10 euros") 
print ("There", g, "ticket (s) of 5 euros") 
print ("There", h, "currency (s) of 2 euros") 
print ("There", i, "currency (s) of 1 euros") 

对于我分解方案硬币数量欧元的我的程序不的你多少张门票有一些欧元计。当执行它时执行条件,如果另一个也执行我。 当它经历倒数第二个周期时,它也评估我并显示另一个。我能做些什么,因为我想

+0

申请编码的Python的基础知识:使用有意义的变量名;学会正确缩进你的代码;应用DRY原则(不要重复自己:使用函数或循环来重复代码而不是复制粘贴代码)。 – agtoever

回答

0

我无法将你的代码放到一个工作版本转换由于巨大的语法错误的量,所以我写了我自己的

num = int(input("Please enter an amount in euros: ")) 

banknotes = { 
    500: "500 euro banknote (s)", 
    200: "ticket (s) of 200 euros", 
    100: "ticket (s) of 100 euros", 
    50: "50 euro banknote (s)", 
    20: "ticket (s) of 20 euros", 
    10: "ticket (s) of 10 euros", 
    5: "ticket (s) of 5 euros", 
    2: "currency (s) of 2 euros", 
    1: "currency (s) of 1 euros" 
} 

while num: 
    max_banknote = max(list(filter(lambda y: y <= num, banknotes))) 

    count = num // max_banknote 
    num -= count*max_banknote 
    print("There", count, banknotes[max_banknote]) 
相关问题