结果后返回顶部

我目前正在尝试不同的方法来解决指数(通过加法)。结果一打印出来,我就不能再使用这个程序了。


我试过continue和break,但它们不合适


x = int(input())

y = 0

z = x

while z != 0:

    y += x

    z -= 1

    if z <= 0:

        y *= x

print(y)

我只需要在之前的结果之后再次重新使用该应用程序,并继续使用它直到它关闭。


白衣非少年
浏览 113回答 1
1回答

冉冉说

您需要将所有内容包装在一个while循环中并给出某种类型的退出条件。x = input()while x != 'exit':&nbsp; &nbsp; x = int(x)&nbsp; &nbsp; y = 0&nbsp; &nbsp; z = x&nbsp; &nbsp; while z != 0:&nbsp; &nbsp; &nbsp; &nbsp; y += x&nbsp; &nbsp; &nbsp; &nbsp; z -= 1&nbsp; &nbsp; &nbsp; &nbsp; if z <= 0:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y *= x&nbsp; &nbsp; print(y)&nbsp; &nbsp; x = int(input())print('You chose to end the program, goodbye!')
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python