-1

I'm currently experimenting on different ways to solve exponents(via addition). As soon as the results are printed, I could not use the program anymore.

I've tried continue and break, but they're not appropriate

x = int(input())
y = 0
z = x
while z != 0:
    y += x
    z -= 1
    if z <= 0:
        y *= x
print(y)

I just need to re-use the application again after the previous results, and keep using it until it is closed.

vonvon
  • 25
  • 1
  • 4
    Possible duplicate of [How to make program go back to the top of the code instead of closing](https://stackoverflow.com/questions/18791882/how-to-make-program-go-back-to-the-top-of-the-code-instead-of-closing) – walnut Sep 19 '19 at 22:10
  • Possible duplicate of [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) – Peter Wood Sep 19 '19 at 22:11

1 Answers1

1

You will need to wrap everything in a while loop and give some type of exit condition.

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!')
Kevin Welch
  • 1,488
  • 1
  • 9
  • 18