+ 2
Python end=""
I was making a simple password generator. The user puts in the how long they want there password to be and it generates a password for them. I'm just wondering, the code below is there any chance instead of using end="" to print the password all on the same line that i could use the * operator. Like print("?" * 4) print "?" 4 times all on the same line. I tried multiple different ways but I couldn't get it really how I want it too. is it even possible to do it that way? https://www.sololearn.com/compiler-playground/c1NVorHhJKzj
9 Respuestas
+ 13
Justice thanks!
Your Mom ,
we can simplify the generation of the password by using the random method *choices* instead of *choice*. we can use it like:
password_random = random.choices(password, k=password_length)
it generates the requested number of characters (k=...) in one go, so we can omit the for loop. the result of this line is a list of characters, that can be joined to a string for output.
then just print the password without any additional arguments.
+ 7
Your Mom ,
the link does not work, i can't see your code.
> can you add the link by using the '+' symbol and *insert code*?
+ 4
Here is the app link for anyone on mobile trying to help:
Edit to add AgentSmith's code.
https://code.sololearn.com/c1NVorHhJKzj/?ref=app
https://code.sololearn.com/cuBW8LBURGZf/?ref=app
+ 2
Can you elaborate on the end goal that you're trying to do? Want to make sure I understand what you're asking. You're wanting it to print the password 4 times or give them 4 options or something? Or just not wanting to use end=""?
Dunno if this helps, give me more info and I'll let ya know if we can figure it out:
https://www.sololearn.com/compiler-playground/cuBW8LBURGZf
+ 2
Im basically just asking instead of printing everything on the same line using end=“” can i use the * operator which can also print things on the same line if that makes sense.
+ 2
No probs!
+ 2
Lothar Thanks, i didnt know that was a thing until now
+ 1
Thanks Justice