Reputation: 944
import sys
import time
start = time.time()
key = input('Type your key:')
x = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'1', '2', '3', '4', '5', '6', '7', '8', '9')
for x1 in x:
for x2 in x:
for x3 in x:
y = (x1+x2+x3)
print (y)
if y == key:
print('Founded')
exit()
done = time.time()
elapsed = done - start
print(elapsed)
The code don't stop using the exit(), the program must finish all possibilities to stop.
Upvotes: 0
Views: 223
Reputation: 1486
You should put it inside of function and use return with "founded" flag.
There is no reason to use of exit()
for such a trivial thing.
import sys
import time
def check():
for x1 in x:
for x2 in x:
for x3 in x:
y = (x1+x2+x3)
print (y)
if y == key:
return True
return False
start = time.time()
key = input('Type your key:')
x = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'1', '2', '3', '4', '5', '6', '7', '8', '9')
res = check()
if res:
print("Found")
done = time.time()
elapsed = done - start
print(elapsed)
Upvotes: 1