2

Hi i wanted to know how to freeze a programm in python.

from time import *
from sys import *
caractère = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#$%&'()*+,-./:;<=>?@[\]^_`{|}~").lower()
a = int(input("The number of character in the password: "))
print("The password is:")
for i in range(a):
    password = ""
    cara = choice(caractère)
    print(cara, end='')

At the end i want to see the password but i can't because the programm the program closes automatically. Can we do it? Thanks

vnk
  • 1,060
  • 1
  • 6
  • 18
Nathor69
  • 35
  • 4
  • 2
    For example, you may add additional `input()` at the end of the code. The program will not close until you type something. – Kate Melnykova Sep 30 '21 at 16:40
  • Does this answer your question? [Python, Press Any Key To Exit](https://stackoverflow.com/questions/11876618/python-press-any-key-to-exit) – jarmod Sep 30 '21 at 16:43

2 Answers2

0

You can add an input() statement at the end of the program so it will close itself as soon as you click any key and press enter. You can also add time.sleep(N) to close the program automatically after N seconds.

Jonathan1609
  • 1,809
  • 1
  • 5
  • 22
0

You can also use any sort of if statement to close the program

from time import *
from sys import *
from random import choice

caractère = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#$%&'()*+,-./:;<=>?@[\]^_`{|}~").lower()
a = int(input("The number of character in the password: "))
print("The password is:")
for i in range(a):
    password = ""
    cara = choice(caractère)
    print(cara, end='')

close_it = input("Press ENTER to exit: ")
if len(close_it) >=0:
    print("Program Ended")

The close_it will trigger after printing the password and if you press enter it will check the length of input and print Program Ended in any case if you give the input or not as it's going to be always true.

Faisal Nazik
  • 2,367
  • 4
  • 17
  • 40