Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I only have emoticons and not text

I want to make a generator of random letters, but instead of letters I only have emoticons. Here is the code.

import random
from random import randint

#random number of characters
sym=random.randint(100,500)
num=0
bn=[]

while num < sym :
    rb=random.randint(0,1)
    bn.append(rb)
    num+=1 
print(bn) #for check

bn=str(''.join(map(str, bn)))



def decode(lst):
    txt= ''.join(map(lambda x: chr(int(x,2)), lst))
    print("txt=",txt)


decode(bn)

The code should be letters or even numbers, but don’t smile! I tried all the ways I could think of, but the result is the same

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Here how to use random.choice to pick a random string.

import random

sym=random.randint(100,500)
alphabet = "abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"

bn=[]
for _ in range(sym):
    bn.append(random.choice(alphabet))
bn = ''.join(bn)
print(bn)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading