Greetings,
I would like to make a programm that would generate a long string of numbers or characters in the way that the user firts states how long the so called word should be (let's say 10 000) and will also state the rules for creating the word: i.e. 1 will change to 001 and 0 will change to 010.

(this program will later be used to research some characteristics of this kind of words)

I would like to ask, which programming language is the best to programm this. I have never tried Python before, but somebody mentioned it could be appropriate.

Thanks a lot!

Python would be easy to do this in. You could use a mixture of the random module as well as the String module and combining them together to get something that does it for you. In fact i will show you how i would do it if i was making a program that made a random string.

import random
import string

r = input("How long should the string be?")
s = ""
for number in range(r):
    s += string.lowercase[random.randint(0,26)]
print s

Thanks a lot, I will start with Python then.

If I read your question correctly, you are thinking about something like that ...

# create a string of random '0' and '1' characters
# then replace '0' with '001' and '1' with '010'

import random

size = int(raw_input("How long should the string be?"))

# only the characters in the list can appear in the string
# add more characters if you need them
choice_list = ['0', '1']

s = ""
for k in range(size):
    s += random.choice(choice_list)

print s

# replace '0' with '001' and '1' with '010'
s2 = ""
for c in s:
    if c == '0':
        c = '001'
    elif c == '1':
        c = '010'
    s2 += c
    
print s2

"""
my output for example -->
110001101011
010010001001001010010001010001010010
"""

Thank you a lot,

the task is actually a slightly different, because, the program should start with 0. Lets say the user states that the substitutions for 0 is 001 and for 1 is 010. So the program will start with 0 and will work in the way that it substitute 0 for 001, then it substitute both 0z and 1, sothe next step will be 001001010. And this way it continues until the length of the string is as big as the user has said in the beginning.

But thank you very much for your answer it gives me idea about how a python program looks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.