Hey I think you might be able to see what I am trying to do here, here is the code I have came up with
import random
print "hello this is the decypher\n"
persons_word = raw_input("Enter your word: ")
print persons_word.random.randrange()
raw_input("Press the enter key to quit")
I am pretty sure the random.randrange is where I am going wrong
What I am trying to do is get a word from the user and jumble it up so if they typed something like this: "galaxy" python will return several words what "galaxy" can make for instance
"galayx"
"algyxa"
if you see what I am trying to do and know how to help please respond!
Help! Trying to jumble a users input
Started by Sp32, Aug 24 2007 07:06 PM
4 replies to this topic
#1
Posted 24 August 2007 - 07:06 PM
|
|
|
#2
Posted 24 August 2007 - 10:31 PM
You're on the right track. The function you're looking for is not random.randrange, but random.shuffle. It'll do the job for you.
import random
word = list(raw_input("Enter a word: "))
random.shuffle(word)
word = ''.join(word)
print "The jumbled word: %s" % word
Notice that we're working with lists. random.shuffle takes a list, so we need to convert our user input from string => list. When we've shuffled the word, we uses join to make the list => string.
#3
Posted 25 August 2007 - 12:08 AM
Thanks for your help but looking at this makes me think I still need to learn alot!
I have never head of .shuffle or .join and not sure what the
%s" % word
bit does
I have never head of .shuffle or .join and not sure what the
%s" % word
bit does
#4
Posted 25 August 2007 - 12:39 AM
"Sp32" said:
I have never head of .shuffle or .join
"Sp32" said:
I have never head of .shuffle or .join and not sure what the
%s" % word
bit does
%s" % word
bit does
print "Integer: %d" % one_parameter print "Integers: %d and %d" % (one_parameter, two_parameters)As you see it looks better, than the following. It's also easier to handle, when you're working with bigger messages.
print "Integer: " + one_parameter print "Integers: " + one_parameter + " and " + two_parameters
#5
Posted 25 August 2007 - 09:55 AM
Thanks for your help and your time, I was using the + sign cause the book I am learning from told me about it :]


Sign In
Create Account


Back to top









