mercredi 13 février 2019

Variable Not Defined After Conditions

This is supposed to be a passcode generator program in Python 3.

    import string
    from random import *

    print("Type Yes or No For The Following Questions:")

    letters = raw_input("Do you want letters in your passcode?" )
    if raw_input == 'Yes': chars1 = string.ascii_letters 
    elif raw_input == 'No': chars1  = ""

    digits = raw_input("Do you want digits in your passcode?" )
    if raw_input == 'Yes':chars2 = string.digits
    elif raw_input == 'No': chars2 = ""

    symbols = raw_input("Do you want symbols in your passcode?" )
    if raw_input == 'Yes': chars3 = string.punctuation 
    elif raw_input == 'No': chars3  = ""

    requestedlength = input("What passcode length do you want? Type any   number: ")
    length = int(requestedlength)

    chars = chars1 + chars2 + chars3

    passcode = raw_input("Type Enter To Generate Random Passcode: ")
    print("".join(choice(chars) for x in range((length))))

What am I doing wrong here? The error states that chars1 chars2 and chars3 are not defined. How would I define those variables after they get altered in the conditional statements? I'm pretty new to Python so I apologize if the code is a mess :(

Thanks, Jason

Aucun commentaire:

Enregistrer un commentaire