forked from hariom20singh/python-learning-codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15.py
More file actions
51 lines (40 loc) · 1.22 KB
/
15.py
File metadata and controls
51 lines (40 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Python program to generate and match
# the string from all random strings
# of same length
# Importing string, random
# and time modules
import string
import random
import time
# all possible characters including
# lowercase, uppercase and special symbols
possibleCharacters = string.ascii_lowercase + string.digits + string.ascii_uppercase + ' ., !?;:'
# string to be generated
t = "tytgj"
# To take input from user
# t = input(str("Enter your target text: "))
attemptThis = ''.join(random.choice(possibleCharacters)
for i in range(len(t)))
attemptNext = ''
completed = False
iteration = 0
# Iterate while completed is false
while completed == False:
print(attemptThis)
attemptNext = ''
completed = True
# Fix the index if matches with
# the strings to be generated
for i in range(len(t)):
if attemptThis[i] != t[i]:
completed = False
attemptNext += random.choice(possibleCharacters)
else:
attemptNext += t[i]
# increment the iteration
iteration += 1
attemptThis = attemptNext
time.sleep(0.1)
# Driver Code
print("Target matched after " +
str(iteration) + " iterations")