How can we generate random alphabets in a single line | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

How can we generate random alphabets in a single line

Output : aksjskahshsuun

8th Jun 2019, 1:26 PM
Y AD ƙ
Y AD ƙ - avatar
7 Respostas
+ 13
From random import choices print(''.join(map(chr,choices(range(97,123),k=17)))) print(*map(chr,choices(range(97,123),k=17)),sep='')
8th Jun 2019, 2:53 PM
CĆ©pagrave
CĆ©pagrave - avatar
+ 12
Thanks Diego , edited šŸ˜Š
8th Jun 2019, 4:09 PM
CĆ©pagrave
CĆ©pagrave - avatar
+ 2
You can make a list of all the alphabet numbers, then generate a number between 0 and 25, and then get the index of that number in that list, and you can also repeat it
8th Jun 2019, 2:05 PM
Airree
Airree - avatar
+ 1
Well i didn't get that Airree
8th Jun 2019, 2:08 PM
Y AD ƙ
Y AD ƙ - avatar
+ 1
Here is a simple one: import string import random for i in range(10): print(random.choice(string.ascii_letters))
8th Jun 2019, 2:12 PM
Mo Hani
Mo Hani - avatar
+ 1
Mo Hani... but this will print everything in seperate lines....i wnt it all in a single line
8th Jun 2019, 2:13 PM
Y AD ƙ
Y AD ƙ - avatar
+ 1
Someone posted a similar question in StackOverFlow, there are alot of different answers with working codes, check it: https://stackoverflow.com/questions/2823316/generate-a-random-letter-in-JUMP_LINK__&&__python__&&__JUMP_LINK
8th Jun 2019, 2:27 PM
Mo Hani
Mo Hani - avatar