字符串格式化问题
# 求1—n的和n = int(input('输入n:'))
s = 0
while n >= 1:
s = s + n
n = n - 1
print ('1-%d 求和结果 =%d' % (n,s))
输入n:9
1-0 求和结果= 45
请教:
我如何传入,print( '1-%d 求和结果 =%d' % (n,s)) 中 的参数n,才能正确显示为:1-9 求和结果= 45
n = int(input('输入n:'))
m = n
s = 0
while n >= 1:
s = s + n
n = n - 1
print ('1-%d 求和结果 =%d' % (m,s))
页:
[1]