![]() |
|
#1
|
|||
|
|||
Shifting characters in a string?I've just started to learn how to use python and I'm trying to define a function in python that could shift each characters in a string with a random number.
I was given a hint that using looping would be helpful to complete this exercise. But I have no clue how to manipulate every character in a string. Python Code:
That's as far as I got, but I know its totally incorrect. Can anybody please help me? Last edited by admin : 28-Feb-2009 at 13:43.
Reason: Please insert your example Python codes between [PY] and [/PY] tags
|
|||
|
#2
|
||||
|
||||
Re: Shifting characters in a stirng?As I understand it, you want to shift the characters in a string by x numbers to the right, e.g. "abcd" shifted by 2 becomes "cdab". Is this correct?
What is "s2"? You define it as an empty string yet you never use it. Are you using a user input to determine the random value? You don't have anything to receive that input from the user. (However, if you are simply calling the function manually then you're fine). I don't think you want to be using the ord function. According to the Python documentation, it returns an integer value of the Unicode character. __________________
Start Programming with Python-A beginner's guide to programming and the Python language. ------------- Common Sense v2.0-Striving to make the world a little bit smarter. |
Recent GIDBlog
Accepted for Ph.D. program by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need Code to Reverse words in a string | lief480 | C++ Forum | 7 | 16-Oct-2008 09:51 |
| Determine the number of words and characters | madpotential | Python Forum | 3 | 26-Feb-2008 21:12 |
| Need help printing "Hello" 7 characters high and 5 characters wide | Emmy | C++ Forum | 4 | 15-Aug-2007 08:28 |
| Re: Things to Avoid in C/C++ -- gets() , Part 1 | WaltP | C Programming Language | 5 | 21-Jun-2007 13:13 |
| fast characters in console | svhb | C Programming Language | 10 | 22-Jun-2005 08:13 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The