0

I was wondering how to make a program where the user types a word and then the program jumbles the letters in the word in a random way.

I've thought a lot about this and failed. I made the program below but its not good at all because I want to jumble the letters and this program just randomly assigns each index one of the letters. This means the same letter can repeat itself several times, like for example: Input: apple. Output: ppppp

import random

print('Type a word!')
i = 0
wordJ = ''

word = input()
word = str(word)
while i < len(word):
    wordJ = wordJ + word[random.randrange(len(word))]
    i = i + 1

print(wordJ)
SiHa
  • 7,830
  • 13
  • 34
  • 43
HeliumBalloon
  • 11
  • 1
  • 2
  • 2
    You already have the random module, just use `random.shuffle`. – Morgan Thrapp Sep 27 '16 at 17:54
  • Is this homework? This feels like homework... Specially with the *"I was wondering how..."* falls in line with the *"I was teaching myself..."* and learning how to shuffle.. see http://stackoverflow.com/a/473983/1111028 – scaryrawr Sep 27 '16 at 17:59

2 Answers2

0

Once you have the string in word you could shuffle it like this

from random import shuffle
word = list(word)
shuffle(word)
word = "".join(word)
print(word)
saurabh baid
  • 1,819
  • 1
  • 14
  • 26
-1
import random

word = input()
word = list(word)
random.shuffle(word)

wordJ = ''.join(word)
print(wordJ)
bmurr
  • 121
  • 1
  • 8