Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Need Help#44

ClosedUnanswered
GGDavo asked this question inQ&A
Jul 23, 2023· 1 comment
Discussion options

I'm very new to Python. Just started a college course on it in May 2023. Currently working on building and improving my first simple application as a Final Project for the class. It is a beginner project.

The main goal is to create a password generator that takes user input for how many passwords to generate and the length of the passwords. Then it will request input on whether the user wants to save the passwords to a file. There is a menu item ("list") that is supposed to list the saved passwords from the previously saved file, but the output shows nothing and loops back to the command input.

I would appreciate any feedback on what I'm doing wrong or can improve in the overall code.

I'm also very new to GitHub so forgive me but I'll post the code I have so far here:

import random, csv

#generates passwords with special requirements
def get_passwds(num, length):
#defines character set
lettrs = "qwertyuiopasdfghjklzxcvbnm"
numbrs = "0123456789"
spchar = "!@#$%&*"
uppr = lettrs.upper()

#combines character sets
pswdChars = lettrs + numbrs + spchar + uppr

pwds = []
for i in range(num):
pwd = "".join(random.sample(pswdChars, length))

#checks password for requirements and append to list of passwordswhile not (any(char.isdigit() for char in pwd) and any(char.isupper() for char in pwd)           and any(char in spchar for char in pwd)):    pwd = "".join(random.sample(pswdChars, length))pwds.append(pwd)

return pwds
def save_pwds(pwds):
with open("pwds.txt", "a") as file:
#writer = csv.writer(file)
for pwd in pwds:
file.write("{pwd}\n")
#writer.writerow([pwd])

def list_pwds():
with open("pwds.txt") as file:

#reader = csv.reader(file)for line in file:    print(line, end="")print()

def menu():
print("What would you like to do?")
print("list - List saved passwords.")
print("new - Get new passwords.")
print("exit - Leave the program.")
print()

#Application for generating a list of strong passwords at a length the user chooses
def main():

print(f"\tBrickWall\nThe Password Generator")
print()

menu()

more = "y"
while True:
command = input("Command: ")
if command == "new":

    pwdnum = int(input("How Many Passwords: "))    pwdlength = int(input("Input Password Length: "))    pwds = get_passwds(pwdnum, pwdlength)    for pwd in pwds:        print(pwd)        print()    while True:        savePwd = input("Would you like to save your passwords? (y/n): ")        if savePwd.lower == "y":            save_pwds(pwds)        else:            break            elif command == "list":    list_pwds(file)    elif command == "exit":    breakelse:    print("Invalid Command! Please try again.\n")    more = input("what would you like to do?: ")print()

print("Bye")
if name == "main":
main()

You must be logged in to vote

Replies: 1 comment

Comment options

Hi, this forum is not here for homework help. It's only purpose is for helping students in this particular course. Sorry, I can't help with this.

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@GGDavo@mikeckennedy

[8]ページ先頭

©2009-2025 Movatter.jp