Write a PYTHON function to get the input from the user to go with words given on the fly (input through keyboard) or read it from a file. At least it should contain a single word otherwise throw an error to the user rather than showing a PYTHON error.
Shuffle letters of words evenly and oddly except the first and last character when we run it again and again. You need to store the modified one so everytime you run it changes. Keep the odd one in one color and even in another color and keep black for the first and last character
Adcricnog to reacersh at an Engslih Urvtisniey, it deosn't mttear in waht oedrr the ltreets in a wrod are, the olny itopmanrt tih
import random
def shuffle(wd):
random.seed()
wd = list(wd)
random.shuffle(wd)
if len(wd) > 2:
wd = [wd[0]] + random.sample(wd[1:-1], k=(len(wd) - 2)) + [wd[-1]]
return ''.join(wd)
str1=input("Enter a string to shuffle: ")
print(shuffle(str1))
Comments
Leave a comment