Python code challenge | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Python code challenge

Can someone help me with a python code that generates more than 20 random characters

20th Nov 2020, 8:36 AM
Izaiah Kay
Izaiah Kay - avatar
7 Answers
20th Nov 2020, 9:24 AM
Izaiah Kay
Izaiah Kay - avatar
+ 6
Where's your attempt?
20th Nov 2020, 8:42 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 6
To generate multiple random characters , using choices() is always a good idea. The code gets shorter and still has a good readability. You can further do an optimization in limiting the import of not necessary functions / methods. Instead of importing module string completely, or module random completely, you can do it like this: from string import ascii_lowercase as asc_lo from random import choices print(''.join(choices(asc_lo, k=42)))
20th Nov 2020, 12:00 PM
Lothar
Lothar - avatar
+ 4
NotAPythonNinja thank you But your code prints separate characters.. I wanted one that prints a string of text
20th Nov 2020, 9:17 AM
Izaiah Kay
Izaiah Kay - avatar
+ 3
CarrieForle I'm Still figuring it out 😃 Trying to debug it
20th Nov 2020, 8:44 AM
Izaiah Kay
Izaiah Kay - avatar
+ 3
I've tried but it seems to have bugs Someone should help me out https://code.sololearn.com/c64DCh53HoC2/?ref=app
20th Nov 2020, 8:57 AM
Izaiah Kay
Izaiah Kay - avatar
+ 3
Lothar thanks alot
21st Nov 2020, 11:42 AM
Izaiah Kay
Izaiah Kay - avatar