-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSentence scrambler.py
More file actions
40 lines (38 loc) · 1.02 KB
/
Sentence scrambler.py
File metadata and controls
40 lines (38 loc) · 1.02 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
from random import randint
def scramble_word(word):
ipls = list(word)
c = 1
opls = []
while (c < (len(ipls) - 1)):
char = ipls[c]
randnum = randint(0, len(opls))
opls.insert(randnum, char)
c = c + 1
op = str(ipls[0])
for c in range(0, len(opls)):
op = op + str(opls[c])
if (len(ipls) > 1):
op = op + str(ipls[(len(ipls) - 1)])
return(op)
op = ""
c = 0
ip = input("Enter sentence: ")
ipls = list(ip)
while (c < len(ipls)):
word = ""
char = ""
mixed = "false"
tries = 0
while (mixed == "false"):
while (char != " " and c < len(ipls)):
char = str(ip[c])
if (char != " "):
word = word + char
c = c + 1
mixedword = scramble_word(word)
tries = tries + 1
if (len(list(word)) <= 3 or mixedword != word or tries > 100):
mixed = "true"
print (word , " ---> " , mixedword)
op = op + mixedword + " "
print(op)