f = ""
s = ""
i = 1
sum = 0
while i < 100:
if i %2 == 1 and i < 99:
f = "-"
sum = sum + i
elif i == 99:
f = "="
sum = sum + i
elif i %2 == 0:
f = "+"
sum = sum - i
s = s + str(i) + f
i += 1
print(s,sum)
#同时我也看到有人这样写的,有启发。。。
s = ""
start = 1
sum = 0
while start < 100:
temp = start % 2
if temp ==1:
if start ==1:
s = str(start)
else:
s = s + "+" + str(start)
sum = sum + start
else:
s = s + "-" +str(start)
sum = sum - start
start += 1
print(s)
print(sum)
#我发现人的想象力真是无穷的,这虽然把问题复杂了想,但也能很好解决问题就是最后一个等号没有打印