Nikolay Petrov
Nikolay Petrov

Reputation: 71

Python3 - Keep the program running after completing the script

Title basically says it all. This is my script:

    keepProgramRunning = True
a = int(input("Type a value for a: "))
b = int(input("Type a value for b: "))
print("Result when multiplying: ", a*b)
print("Result when dividing: ", a/b)
print("...", a-b)
print("...", a+b)

How can i see the results after i typed a value of a and b without cmd automatically closing.

Upvotes: 0

Views: 287

Answers (2)

Junuxx
Junuxx

Reputation: 14261

The simplest way would be to wait for user input

Add this at the end:

input("Press enter to close")

Alternatively, if you run the script from command line, the window won't disappear after the script ends.

Upvotes: 3

Bob
Bob

Reputation: 1497

Wait for another input

keepProgramRunning = True
a = int(input("Type a value for a: "))
b = int(input("Type a value for b: "))
print("Result when multiplying: ", a*b)
print("Result when dividing: ", a/b)
print("...", a-b)
print("...", a+b)
input("Press [enter] to continue..")

Upvotes: 1

Related Questions