Can you show us your attempt?
Cheers,
Chris
Hi, to be honest i'm a newbye so i don't know where to start, i began
in this way but i don't know how to proceeed.
list = (EE472A86441AF2E629DE360)
Thanks
What does "change each digit with a random digit"? Do you want to swap two
random elements of the sequence with each other? The "random" module
contains a tool to generate random permutations, all you would have to do
is to split the string into a list, call that function and later join the
results.
Uli
--
Domino Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
> On Mar 15, 9:20 am, Chris Rebert <c...@rebertia.com> wrote:
> > Can you show us your attempt?
>
> Hi, to be honest i'm a newbye so i don't know where to start
Work through the entire Python tutorial, in sequence
<URL:http://docs.python.org/tutorial/>. Not merely read: work through
it, reading the explanations, performing the examples, and experimenting
with them until satisfied you understand, before moving on to the next.
--
\ “I was gratified to be able to answer promptly and I did. I |
`\ said I didn't know.” —Mark Twain, _Life on the Mississippi_ |
_o__) |
Ben Finney
This can be a way to begin :
s="EE472A86441AF2E629DE360"
for a in s:
print a
The following is a very basic trick to build a list <t> containing the
elements of the string <s>
s="EE472A86441AF2E629DE360"
t=[]
for a in s:
t.append(a)
All that you have to change is t.append(a) into something that
tests if a is a number and append something else in that case.
Depending what you want, you can even do
s.replace("1","ONE").replace("2","TWO").replace("3","FIVE")
This is however far from being random ;)
Have good tests
Laurent
"list" is a builtin type, so you shouldn't use it as name for other things.
The thing on the right-hand side of the assignment is just the identifier
EE47... after stripping the brackets, which don't have a meaning there.
I'd suggest that you start reading a Python tutorial to get some basics down
first. Start reading at http://docs.python.org.
Laurent thanks a lot very much!!! really appreciated it.. now i have a
good start point thanks again
Something like that but it append A to each element of the string
string = "EE472B"
t = []
for x in string[:]:
print t.append("A") #i don't want to append A, the final
result is EAEA4A7A2ABA
# i would like to substitute each element with a random
string
How i can use the random module in this case? Thanks
As it, it prints "None" 6 times. Then t is ['A','A','A','A','A']
What you have to do is to read about basic python. Search for python
tutorial on the net.
Then try the following exercices :
Exercises
1
print the first 1000 intergers
2
print the sine of 1 ... 1000
3
print the intergers x between 1 and 1000 such that cos(x) is between 0
and 0.5
Have a good afternoon
Laurent
As it, it prints "None" 6 times. Then t is ['A','A','A','A','A']
hi
I'm not an experienced python programmer but the following code should
work:
# you need to import the random module to get random numbers
import random
# convert the string in a list (as string are read-only)
l = list('EE472A86441AF2E629DE360')
# initialize the random generator
random.seed()
# index
i = 0
# loop through the characters in the list
for c in l:
# if the current character is a digit
if c.isdigit():
# get a random integer in the 0-9 range
# convert it to a string and replace the old value
l[i] = str(random.randint(0,9))
# increment the list index
i +=1
# convert the modified list back to string and display it
print(''.join(l))
--
bye
!(!1|1)