Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with my code
#1
Hi all,

I have been working on my code but I am a novice and I am still trying to get my head around it all. I can't get the output I am looking for. Everything I have tried doesn't work and I am close to pulling my hair out lol! Any help would be much appreciated but I am not looking for others to do the work for me! Just need help getting to the answer. Thank you.

The assignment is:
"For every incorrect password length, the program will record an entry in a password log file that will include the date/time (updated to the nearest microsecond) and the reason why the password is invalid either “password < 6” or “password >10”. The file will not store any passwords. Once the length is valid, the program will output the length of the password and determine if the password is weak or strong as in the previous version. The program will then output each line of the password log file to the screen."

Problem 1.
I now have the output with the date, time and the reason why on one line e.g. 2023-09-07 18:55:45.427403 password > 10.
I want to put a comma after the time and before the word password e.g. 2023-09-07 18:55:45.427403, password > 10. I have tried many variations, but I get a squiggly line and/or the code doesn't work.

Problem 2.
I have followed the examples/exercises that we have been given but I don't think the input/output coding is correct. If it's not, I don't know what is incorrect! I have attached new screenshots of the outputs.

import datetime


def main():
    input_file = open("password_log.txt", "r")

    for line in input_file:
        print(line, end='')

    input_file.close()



# INPUT
MIN_PASSWORD_LENGTH = 6
MAX_PASSWORD_LENGTH = 10
output_file = "password_log.txt"
password = input("Enter your password. It must be a minimum of 6 and a maximum of 10 characters. ")
password_length = len(password)
# OUTPUT
if len(password) < 6:
    print(f"Your password has {len(password)} characters and is too short.")
    print(datetime.datetime.today(), "password < 6")
    new_password = input("\nEnter your password again. ")
    output_file = open("password_log", "a")
    output_file.write(new_password)
    output_file.write("\n")
    output_file.close()
if len(password) > 10:
    print(f"Your password has {len(password)} characters and is too long.")
    print(datetime.datetime.today(), "password > 10")
    new_password = input("\nEnter your password again. ")
    output_file = open("password_log", "a")
    output_file.write(password)
    output_file.write("\n")
    output_file.close()
if password.isalpha():
    print(f"Your password has {len(password)} characters and is weak. It only contains letters.")
    print(datetime.datetime.today())
elif password.isnumeric():
    print(f"Your password has {len(password)} characters and is weak. It only contains numbers.")
    print(datetime.datetime.today())
else:
    print(f"Your password has {len(password)} characters and is strong. It contains both letters and numbers.")
    print(datetime.datetime.today())
main()
# END

Attached Files

Thumbnail(s)
           
Reply


Messages In This Thread
Help with my code - by bp12 - Sep-06-2023, 03:09 PM
RE: Help with my code - by deanhystad - Sep-06-2023, 07:24 PM
RE: Help with my code - by bp12 - Sep-07-2023, 10:24 AM
RE: Help with my code - by Pedroski55 - Sep-10-2023, 11:41 AM
RE: Help with my code - by deanhystad - Sep-10-2023, 01:33 PM
RE: Help with my code - by Pedroski55 - Sep-11-2023, 05:15 AM
RE: Help with my code - by deanhystad - Sep-11-2023, 02:49 PM
RE: Help with my code - by bp12 - Sep-17-2023, 02:28 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020