What not right with my code? HELP | Sololearn: Learn to code for FREE!

+3

What not right with my code? HELP

https://code.sololearn.com/c4Ae16cqwAlq/?ref=app

8/4/2021 6:57:07 PM

Herbert Ink

15 Answers

New Answer

+7

https://code.sololearn.com/cTNB0waXnokz/?ref=app

+7

Abhay , BootInk , just to make clear how choices() and "".join() is working (together) ▪︎"".join() can take lists and uses the list elements for creating a new string, as long as all elements of the list are strings ▪︎choices() does not return a list of lists, but just a list of strings if the population used in choices() is also a string, a list of strings,.... sample output of choices(): ['s', '-', '+', 'X', '^', 'S', '|', ')']

+1

NDUHURA HERBERT , can you please give a more detailed description about the tutorial and lesson number from which this question is coming? or copy the complete task description. thanks!

+1

Hey a freind had posted a piece of code on Twitter and I had to try it out

+1

The 4th line is highlighted in the IDE

+1

NDUHURA HERBERT , the line that generates the password can be done like this: (you don't needs a range() and choices gets a random length from k= randint(8,16)) all the rest should work. ... password = "".join(choices(ch, k= randint(8,16))) ...

0

Check the fourth line well Thats where you are making a mistake

0

choices is returning list and well join method won't work on list , it only concatenates the string items

0

As mentioned, choices returns a list of lists, rather than just a list of randomly chosen elements. This is problematic because join only works on one dimensional lists. I suggest you define a helper function that can return a one dimensional list of randomly selected characters within your list comprehension, though there might already be a function out there for that purpose...

0

# Created by NDUHURA HERBERT {2} import string as s from random import * ch = s.ascii_letters + s.digits + s.punctuation password = "".join([choices(ch)[0] for _ in range(randint(8, 16))]) print(password)

0

If you remove the "s" in choice, the code works. import string as s from random import * ch = s.ascii_letters + s.digits + s.punctuation password = "".join(choice(ch) for x in range(randint(8, 16))) print(password) https://code.sololearn.com/c9qoG6f1R8d9/?ref=app

0

Thanks Kirabo Ibrahim

0

I need the help to solve problem code.

0

What is your code question? 🤔 Send it here so I can see where you are at? Please provide the code link.

-1

while joining a list, you should join by comma like this ",".join(list) i also past through this problem before