Lost Password?

Go Back   CodeCall Programming Forum > Software Development > Python

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

Python Discussion forum for Python, a high-level language with simple syntax, but yet powerful.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-24-2007, 10:06 PM
Sp32 Sp32 is offline
Newbie
 
Join Date: Aug 2007
Posts: 10
Credits: 0
Rep Power: 0
Sp32 is on a distinguished road
Unhappy Help! Trying to jumble a users input

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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 08-25-2007, 01:31 AM
v0id's Avatar   
v0id v0id is offline
Super Moderator
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,578
Last Blog:
CherryPy(thon)
Credits: 55
Rep Power: 28
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

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.
Code:
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-25-2007, 03:08 AM
Sp32 Sp32 is offline
Newbie
 
Join Date: Aug 2007
Posts: 10
Credits: 0
Rep Power: 0
Sp32 is on a distinguished road
Default

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

Last edited by Sp32; 08-25-2007 at 03:16 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-25-2007, 03:39 AM
v0id's Avatar   
v0id v0id is offline
Super Moderator
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,578
Last Blog:
CherryPy(thon)
Credits: 55
Rep Power: 28
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

Quote:
Originally Posted by Sp32
I have never head of .shuffle or .join
shuffle is a function in the object random. random is just a cl***, which contains data, functions, etc. And so are join, but it's not in the object random, but in str. shuffle shuffles a list in random order, and join puts a list into a concrete object, like a string.

Quote:
Originally Posted by Sp32
I have never head of .shuffle or .join and not sure what the

%s" % word

bit does
It's an easier way to make long messages, containing values, variables, and so on. You could have been using the +operator too, but I prefer this way. One thing you've to remember is, when there's more parameters to the string, then you have to close them in parentheses.
Code:
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.
Code:
print "Integer: " + one_parameter
print "Integers: " + one_parameter + " and " + two_parameters
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 08-25-2007, 12:55 PM
Sp32 Sp32 is offline
Newbie
 
Join Date: Aug 2007
Posts: 10
Credits: 0
Rep Power: 0
Sp32 is on a distinguished road
Default

Thanks for your help and your time, I was using the + sign cause the book I am learning from told me about it :]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[C++] Validating user input Xochiquetzal C and C++ 2 07-08-2007 05:18 PM
PHP: Log Out Users Ronin PHP Forum 3 04-26-2007 09:42 AM
Please Help With A C Program!! siren C and C++ 7 04-17-2007 08:45 AM
Interacting with the Mic input FlyByWire128 General Programming 2 02-23-2007 01:21 PM
Java:Tutorial - User Input John Java Tutorials 0 12-09-2006 07:25 PM


All times are GMT -5. The time now is 08:29 PM.

Contest Stats

Xav ........ 1322.18
MeTh0Dz|Reb0rn ........ 1053.7
morefood2001 ........ 879.43
John ........ 877.37
marwex89 ........ 869.98
WingedPanther ........ 830.24
Brandon W ........ 735.07
chili5 ........ 309.39
Steve.L ........ 236.23
dcs ........ 216.02

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 82%

Ads