J
J
John Smit2020-01-02 19:40:07
Python
John Smit, 2020-01-02 19:40:07

How to replace a random zero with a 1?

import random
b = str(000000)
a = random.randint(1, 6)

What to do next, so that in "b" some zero has changed to the desired number?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dr_mamaev, 2020-01-02
@johnsmit228

import random
b=[]
for i in range(6):
    b.append('0')
a = random.randint(0, 5)
b[a] = '1'
c=''.join(b)
print(c)

A
aRegius, 2021-01-04
@aRegius

from random import sample

b = '100000'
''.join(sample(b, k=len(b)))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question