May-02-2018, 02:42 PM
Hi everyone.
Im trying to make a function that blend randomly the words in a sentence.
Made some checks with print command... ignore it.
Im quite new with python so feel free to advice me what ive done wrong.
Here is my code; it seems like ive done it ok, but something go wrong when I run it :/
Im trying to make a function that blend randomly the words in a sentence.
Made some checks with print command... ignore it.
Im quite new with python so feel free to advice me what ive done wrong.
Here is my code; it seems like ive done it ok, but something go wrong when I run it :/
import random def BlendString(): string = input ("Enter a sentence: \n") s = string.split() i=0 newstring = s print (newstring) rand = random.sample(range(0,len(s)),len(s)) print (rand) while len(s)-1 > i: newstring[i] = s[rand[i]] print (newstring) i+=1 BlendString()