Python end="" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

2nd Jun 2023, 5:39 PM
Junior
Junior - avatar
9 Answers
+ 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.
2nd Jun 2023, 6:13 PM
Lothar
Lothar - avatar
+ 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*?
2nd Jun 2023, 5:58 PM
Lothar
Lothar - avatar
+ 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
2nd Jun 2023, 5:58 PM
Justice
Justice - avatar
+ 4
Lothar It does work, just not for mohile users. See my message. Your Mom is a PC user so he won't have access to the app links so I made it myself.
2nd Jun 2023, 5:59 PM
Justice
Justice - avatar
+ 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
2nd Jun 2023, 5:52 PM
AgentSmith
+ 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.
2nd Jun 2023, 5:55 PM
Junior
Junior - avatar
+ 2
No probs!
2nd Jun 2023, 6:06 PM
Justice
Justice - avatar
+ 2
Lothar Thanks, i didnt know that was a thing until now
2nd Jun 2023, 6:33 PM
Junior
Junior - avatar
+ 1
Thanks Justice
2nd Jun 2023, 6:03 PM
Junior
Junior - avatar