展开全部
题目1if __name__ == '__main__':
number = input("Please input a number:")
number = int(number)
i = 1
sum = 0
output = ""
while i <= number:
sum = sum + i
if i == 1:
output = "1"
else:
output = "%s+%d"%(output, i)
i = i + 1
print("Result: %s=%d"%(output, sum))
运行结果32313133353236313431303231363533e4b893e5b19e31333332616462
题目2if __name__ == '__main__':
number = input("Please input a number:")
number = int(number)
i = 1
while i <= number:
sum = 0
j = 1
output = ""
while j <= i:
sum = sum + j
if j == 1:
output = "1"
else:
output = "%s+%d"%(output, j)
j = j + 1
print("%s=%d"%(output, sum))
i = i + 1
运行结果
题目3if __name__ == '__main__':
number = input("Please input a number:")
number = int(number)
i = 1
while i <= number:
num = 0
j = 1
while j <= i:
num = num * 10 + j
j=j+1
sum = num*8 + i
print("%d*8+%d=%d"%(num,i, sum))
i = i + 1
运行结果
题目4if __name__ == '__main__':
number = input("Please input a number:")
number = int(number)
i = 1
while i <= number:
num = 0
j = 1
while j <= i:
num = num * 10 + j
j=j+1
sum = num*9 + (i+1)
print("%d*9+%d=%d"%(num,i+1, sum))
i = i + 1
运行结果