+ 1
Frequency Stability Property
Currently, I’m working on showing how the Frequency Stability Property works. The next step in my code involves the ability to select every three digits in each sequence, which I don’t know how to do. Below is a link to what I have so far: https://sololearn.com/compiler-playground/cG6UYv1rY4VY/?ref=app
5 Respostas
+ 2
or use list comprehension
import random
s1 = "".join(str(random.randint(0,1)) for _ in range(100))
print(s1)
n = 3
grouped = [s1[i:i+n] for i in range(0,len(s1),n)]
print(grouped)
s2="".join("0" if random.random()<0.5 else "1" for _ in range(100))
print(s2)
n = 3
grouped = [s2[i:i+n] for i in range(0,len(s2),n)]
print(grouped)
+ 1
import random
import textwrap
s1 = "".join(str(random.randint(0,1)) for _ in range(100))
print(s1)
grouped = textwrap.wrap(s1,3)
print(grouped)
+ 1
Thanks, Bob_Li
0
also, counting 1 and 0 can be simpler
s1_zc = s1.count("0")
s1_oc = 100 - s1_zc
0
Any inbox numbers for chatting