Python Forum
what's wrong? i know this is simple
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what's wrong? i know this is simple
#9
Another way. generates a random 10 character password

import os
from random import choices
from string import digits, ascii_letters

# Define a function to generate and return a 10 character password
def generate():
    characters = digits+ascii_letters+'@#$&!'
    return ''.join(choices(characters, k=10))

# Define a function to clear the terminal
def clear():
    return os.system('cls' if os.name == 'nt' else 'clear')

# Start the loop
while True:
    # Clear the terminal, generate a password and ask for password
    clear()
    mypassword = generate()
    password = input('What is the password?: ')

    # Check if password matches
    if password == mypassword:
        # Password matches do stuff
        print('Password matched')
    else:
        # Password does not match
        print('Password does not match')
        print(f'Password is {mypassword}')

    # Ask to go again ask is forced to lower case
    ask = input('Try again?: ').lower()

    # if ask is y or yes go again else exit
    if ask in ['yes', 'y']:
        continue
    else:
        clear()
        print('Goodbye!')
        break
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts


Reply


Messages In This Thread
what's wrong? i know this is simple - by davidorlow - Mar-15-2023, 12:47 AM
RE: what's wrong? i know this is simple - by menator01 - Mar-15-2023, 08:50 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 1,301 Nov-07-2023, 04:32 PM
Last Post: snippsat
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 5,206 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  python gives wrong string length and wrong character thienson30 2 4,026 Oct-15-2019, 08:54 PM
Last Post: Gribouillis
  simple dragon realm gone wrong Darbandiman123 7 7,260 Mar-01-2017, 05:25 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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