您需要将所有内容包装在一个while循环中并给出某种类型的退出条件。x = input()while x != 'exit': x = int(x) y = 0 z = x while z != 0: y += x z -= 1 if z <= 0: y *= x print(y) x = int(input())print('You chose to end the program, goodbye!')