۲ دانشجوی سون‌لرن
تغییر جزئی کد
جامعه پایتون (وب) ایجاد شده در ۲۹ تیر ۱۴۰۲

ظاهرا این کد با اونی که استاد نوشتن یه فرق کوچیک داره که لازم نمیشه توی ویندوز از خط فرمان استفاده کنیم؟!. ممنون میشم توضیح بدید :

     

   

# Importing the required modules
import string
# Importing the random module to generate random passwords
from random import choices
# Defining the function to create a password
def create_password(length=8, upper=False, lower=False, digit=False, pun=False):
    # Creating an empty string to store the pool of characters
    pool = ''
    # Adding the upper case letters to the pool if requested
    if upper:
        pool += string.ascii_uppercase
    # Adding the lower case letters to the pool if requested
    if lower:
        pool += string.ascii_lowercase
    # Adding the digits to the pool if requested
    if digit:
        pool += string.digits
    # Adding the punctuation marks to the pool if requested
    if pun:
        pool += string.punctuation
    # Using the default pool of letters if none is requested
    if pool == '':
        pool = string.ascii_letters
    # Returning a random password of the given length from the pool
    return ''.join(choices(pool, k=length))
# Checking if the script is run directly
if __name__ == '__main__':
    # Asking the user for the password length and types of characters
    length = int(input("Length of password: "))
    upper = input("User Upper case (y/n): ") == 'y'
    lower = input("User lower case (y/n): ") == 'y'
    digit = input("User digit case (y/n): ") == 'y'
    pun = input("User punc case (y/n): ") == 'y'
    # Printing a random password using the create_password function and the user inputs
    print(create_password(
        length, upper, lower, digit, pun
    ))

سلام علی جان میتونید این کد رو به صورت cmd ران کنید

امیداوارم منظورتون درست متوجه شده باشم

بهترین پاسخ
پوریا شفیعی ۲۹ تیر ۱۴۰۲، ۱۸:۲۲

پس یعنی با اسکریپتی که استاد توی ویدیو زده ن کاملا یکسانه؟!. شاید یک دستورش فرق داشته باشه...

منظورم این بود.

علی نعیمی ۳۰ تیر ۱۴۰۲، ۰۷:۱۶