【问题标题】:Hi I need help for loops嗨,我需要循环帮助
【发布时间】:2016-10-17 13:59:54
【问题描述】:

所以我写了代码,所以它会打印 m-(m%10),我希望它打印:加上这个数字,直到 %10 将是 0。任何帮助将不胜感激。抱歉英语不好。我写的代码在下面。

a=int(input('X= '))
b=int(input('Y= '))
c=int(input('C= '))
d=int(input('D= '))
e=int(input('E= '))
f=int(input('F= '))
j=a+b+c+d+e+f
numbers=[a,b,c,d,e,f] 
for i in (numbers):
    if i%2==1:
            m=j-i
            print(m-(m%10))
    elif i%2==0:
            m=j
            print(m-(m%10))

【问题讨论】:

标签: python loops


【解决方案1】:

如果我理解你的意图,你想要的打印值

a
a + b
a + b + c
a + b + c + d
a + b + c + d + e
a + b + c + d + e + f

但并非总是如此 - 当总和可被 10 整除时,您希望停止。

如果这是你需要的,这里是代码:

a = int(input('A = '))
b = int(input('B = '))
c = int(input('C = '))
d = int(input('D = '))
e = int(input('E = '))
f = int(input('F = '))

numbers = [a, b, c, d, e, f]
sum     = 0 

for i in numbers:
    sum = sum + i
    print(sum)
    if sum % 10 == 0:
       break

【讨论】:

    猜你喜欢
    • 2013-05-24
    • 1970-01-01
    • 1970-01-01
    • 2014-09-30
    • 2021-05-14
    • 1970-01-01
    • 1970-01-01
    • 2019-06-07
    • 2019-10-28
    相关资源
    最近更新 更多