I'm try to make this: your enter a word like this: Happy and than the program returns somethings like : yppaH or appHy.
The problem is that I get just one letter : y or H, etc..
import random
def myfunction():
"""change letter's position"""
words = input("writte one word of your choice? : ")
words = random.choice(words)
print('E-G says : '+ words)
You have to use sample, not choice.
import random
# it is better to have imports at the beginning of your file
def myfunction():
"""change letter's position"""
word = input("writte one word of your choice? : ")
new_letters = random.sample(word, len(word))
# random.sample make a random sample (without returns)
# we use len(word) as length of the sample
# so effectively obtain shuffled letters
# new_letters is a list, so we have to use "".join
print('E-G says : '+ "".join(new_letters))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With