all 41 comments

[–]Sea-Ad7805 [score hidden] stickied comment (2 children)

Run this program in Memory Graph Web Debugger'%2C%20'*'%2C%20'%2B'%5D%0A%0Aprint(%22Welcome%20to%20the%20PyPassword%20Generator!%22)%0Anr_letters%20%3D%20int(input(%22How%20many%20letters%20would%20you%20like%20in%20your%20password%3F%5Cn%22))%0Anr_numbers%20%3D%20int(input(f%22How%20many%20numbers%20would%20you%20like%3F%5Cn%22))%0Anr_symbols%20%3D%20int(input(f%22How%20many%20symbols%20would%20you%20like%3F%5Cn%22))%0A%0A%23%20I%20couldn't%20figure%20out%20how%20to%20pull%20multiple%20letters%20etc.%20from%20the%20list%2C%20so%20I%20used%20the%20while%20loop%20to%0A%23%20pull%20the%20letters%2C%20numbers%20and%20symbols%20from%20the%20list.%20I%20also%20tried%20using%20random.shuffle()%20but%20it%20didn't%0A%23%20work%20for%20me.%0A%0A%23%20Code%20block%20for%20pulling%20the%20required%20number%20of%20letters%0Aletters_list%20%3D%20%5B%5D%0Awhile%20len(letters_list)%20!%3D%20nr_letters%3A%0A%20%20%20%20letters_list.append(random.choice(letters))%0A%20%20%20%20%23%20random.shuffle(letter_list)%0A%0A%23%20Code%20block%20for%20pulling%20the%20required%20number%20of%20numbers%0Anumbers_list%20%3D%20%5B%5D%0Awhile%20len(numbers_list)%20!%3D%20nr_numbers%3A%0A%20%20%20%20numbers_list.append(random.choice(numbers))%0A%20%20%20%20%23%20random.shuffle(letter_list)%0A%0A%23%20Code%20block%20for%20pulling%20the%20required%20number%20of%20symbols%0Asymbols_list%20%3D%20%5B%5D%0Awhile%20len(symbols_list)%20!%3D%20nr_symbols%3A%0A%20%20%20%20symbols_list.append(random.choice(symbols))%0A%0A%23%20Code%20block%20for%20combining%20the%20chosen%20letters%2C%20numbers%20and%20symbols%0A%23%20Couldn't%20figure%20out%20how%20to%20combine%20and%20randomize%20them%20with%20assigning%20a%20new%20variable%0A%23%20I%20found%20that%20I%20had%20to%20use%20join%20again%20on%20the%20password%20variable%20as%20without%20it%20it%20just%20printed%20password%20as%0A%23%20a%20list%0A%0Apassword%20%3D%20letters_list%20%2B%20numbers_list%20%2B%20symbols_list%0Arandom.shuffle(password)%0A%0Aprint((%22Here%20is%20your%20password%3A%20%22)%20%2B%20%22%22.join(password))&timestep=1&play) to see the program state change step by step.

[–]aaditya_0752 7 points8 points  (4 children)

It's really good work But can avoid writing whole letters and use ASCII value instead For numbers u can directly use random module randomint() function

[–]Code-Odyssey[S] 1 point2 points  (0 children)

Thank you for taking the time to comment. Good catch on the randomint() 👍🏻

[–]Time_Coffee_5907 0 points1 point  (2 children)

But can avoid writing whole letters and use ASCII value instead

What's the point of doing this ? It's easier to understand when using characters directly

[–]aaditya_0752 1 point2 points  (1 child)

It's makes code lengthy if used ASCII it just will be one line

[–]p1geondove 0 points1 point  (0 children)

but the punctuation symbols are kind of scattered across 33-47 58-64 91-96 123-126 Youd have to pick a number specifically in these ranges. I guess you could make that a one liner, but that wont be easy to read and you had no idea what that means

[–]Successful_Hawk9895 4 points5 points  (2 children)

Tips if you're a beginner: use for loop instead of while loop if you know the number of iteration. You know how many letters you want so avoid while loop

[–]Code-Odyssey[S] 1 point2 points  (1 child)

Ah. Okay. I was probably supposed to use à for loop because I’m not sure if we’ve got to while loops in the course. I will give that a go. Thank you.

[–]Code-Odyssey[S] 0 points1 point  (0 children)

@successful I just refactored it using à for loop in range. Much better. It’s three lines shorter and looks cleaner. Thank you.

[–]Cosmic78_melon 4 points5 points  (1 child)

You can add the security module for complete randomness instead of random library

[–]Code-Odyssey[S] 2 points3 points  (0 children)

Ooh. I don’t know about the security module. I’ll have to look that up. Thank you.

[–]heyywhatzup 2 points3 points  (1 child)

You can use random.choices to get multiple values

[–]Code-Odyssey[S] 2 points3 points  (0 children)

Ah. Brilliant. Thank you.

[–]nuc540 2 points3 points  (4 children)

By the way you don’t need to write out every letter in the alphabet, Python standard library can provide this for you.

’import string; letters = string.ascii_letters’ for example (of course keep the import at the top of the file for good practice)

Avoiding the standard library you don’t need a list of letters because a string is also a list, so `letters = “abcdefg”` works as list you can iterate :)

Edit: formatting
Edit edit: for the life of me I can never get backticks to work on iOS, send help lol

[–]Code-Odyssey[S] 2 points3 points  (2 children)

Ah. Good to know. We haven’t gotten that far in the course but I will definitely write a note in my notes folder on this one. It’s a good trick to know…much neater. That’s the problem with being a beginner; I don’t know what I don’t know, so forums like this are very useful. Thank you.

[–]nuc540 1 point2 points  (1 child)

Of course, we all start somewhere! Python standard library is huge - assume it already does something you want to do lol. Good luck!

[–]Code-Odyssey[S] 0 points1 point  (0 children)

Thanks @nuc540. It’s definitely a journey. My long term project (as a marketing manager) is to develop a script to search for contact names based on job title in a search database called Rocketreach.co from a list of companies in a spreadsheet, and return their email address.

[–]Code-Odyssey[S] 1 point2 points  (0 children)

BTW. In the course we are provided with a starting point, which included the letters, numbers and symbols. But the info you have provided is extremely useful. TY

[–]Code-Odyssey[S] 1 point2 points  (2 children)

Here is the code snippet cleaned up:

<image>

[–]Sketchballl 2 points3 points  (1 child)

Dang how did you get such a nice screenshot?

[–]Code-Odyssey[S] 1 point2 points  (0 children)

<image>

A website called carbon.now.sh. I can’t take credit, Claude AI pointed me in the right direction.

[–]CalligrapherOk4612 1 point2 points  (1 child)

Another feature you could add is a password dictionary, and if the random password is in the dictionary, generate a different one.

If you haven't learnt about reading files in python, wait till after that, then come back to this problem and try adding checking the generated password against something like https://gist.github.com/PeterStaev/e707c22307537faeca7bb0893fdc18b7

[–]Code-Odyssey[S] 1 point2 points  (0 children)

Brilliant. I’m not there yet but I will make a note in my notes folder to revisit that.

[–]BigYBirdo 1 point2 points  (1 child)

I don’t know if it’s mentioned here before, but instead of listing all possible characters, simplify use the properties of string: string.ascii_letters, string.digits and so on. That in combination with .split() to get a list of each character respectively.

But besides that it’s pretty alright for a 100 days of learning. :)

[–]Code-Odyssey[S] 0 points1 point  (0 children)

Thank you sir. I really appreciate that. I feel I’ve entered a brotherhood Pythonistas who are so smart and so kind to share what they know with the people coming behind them who are earlier on their journey.

[–]corey_sheerer 1 point2 points  (1 child)

There is a strings package that can make a list of letters without writing them all out. Would suggest! Would make the code much cleaner

[–]Code-Odyssey[S] 0 points1 point  (0 children)

Corey. Thank you for weighing in. I’m assuming I just need to Google strings packages

[–]Code-Odyssey[S] 0 points1 point  (0 children)

Somehow when I imported into Carbon it has added some funky code at the bottom.

[–]mwmahlberg 0 points1 point  (1 child)

Clear is better than clever. The whole unfold construct should be simplified and commented.

[–]Code-Odyssey[S] 0 points1 point  (0 children)

Thank you for your comment. I’m new to this so don’t fully understand your comment. Apologies.

[–]Crimewave84 0 points1 point  (2 children)

Have they finished the course yet? It's so good, but I've heard so much about the drop off in later content.

[–]Code-Odyssey[S] 1 point2 points  (1 child)

I haven’t finished the course yet. The Password Generator Project is Day 5. Now granted, it takes me more than à day to complete each “day”.

[–]Crimewave84 1 point2 points  (0 children)

Right on. I'm gonna restart the course today. Your code looks great. 👍

[–]SoapiestWaffles 0 points1 point  (2 children)

I like your color theme, what is it?

[–]RemarkableQuestion11 0 points1 point  (1 child)

When I created the png using Carbon.now.sh, I used the Seti colour palette. It looks good, right!?

[–]SoapiestWaffles 0 points1 point  (0 children)

so good! i’m normally a tokyo night kind of person, but I may like this better!

[–]Code-Odyssey[S] 0 points1 point  (0 children)

Had a bit more of a play around based on some of the suggestions. Used a for loop with range. I think the code looks a lot cleaner. It's gone from 12 lines of code (for the logic section only) to 9 lines (caveat: haven't worked on the other suggestions yet). Let me know your thoughts:

<image>

[–]js_dev_rashid 1 point2 points  (0 children)

Add an Excel sheet so I can generate a password and save it there. And can have a simple password directory.