如何用=替换最后一个+?
how to replace the last + with =?
total = 0
number = 1
until = int(input("Until: "))
while total < until:
print(number, end = " + ")
total += number
number += 1
print(total)
你必须添加一个条件来检查你是否已经到达循环的末尾,然后在这种情况下打印'='。像这样。
total = 0
number = 1
until = int(input("Until: "))
while total < until:
total += number
if total >= until:
print(number, end=" = ")
else:
print(number, end = " + ")
number += 1
print(total)
total = 0
number = 1
until = int(input("Until: "))
while total < until:
print(number, end = " + ")
total += number
number += 1
print(total)
你必须添加一个条件来检查你是否已经到达循环的末尾,然后在这种情况下打印'='。像这样。
total = 0
number = 1
until = int(input("Until: "))
while total < until:
total += number
if total >= until:
print(number, end=" = ")
else:
print(number, end = " + ")
number += 1
print(total)