lundi 24 février 2020

Extra unwanted result when generating random number [duplicate]

I wanted to create a random numerical password generator.So, I made one. It works correctly, just like the way i wanted it to work.But there is an extra word printed in the console.

def randgen():
    # import the 'random' module
    import random
    # create variables for each digit in the password
    no1 = 0
    no2 = 0
    no3 = 0
    no4 = 0
    no5 = 0
    no6 = 0
    no7 = 0
    no8 = 0
    no9 = 0
    no10 = 0
    # generate random number for each digit
    # in each iteration
    for x in range(10):
        if x == 0:
            no1 = random.randrange(0, 9, 1)
        elif x == 1:
            no2 = random.randrange(0, 9, 1)
        elif x == 2:
            no3 = random.randrange(0, 9, 1)
        elif x == 3:
            no4 = random.randrange(0, 9, 1)
        elif x == 4:
            no5 = random.randrange(0, 9, 1)
        elif x == 5:
            no6 = random.randrange(0, 9, 1)
        elif x == 6:
            no7 = random.randrange(0, 9, 1)
        elif x == 7:
            no8 = random.randrange(0, 9, 1)
        elif x == 8:
            no9 = random.randrange(0, 9, 1)
        elif x == 9:
            no10 = random.randrange(0, 9, 1)

    # print all the digits concatenated
    print(no1, no2, no3, no4, no5, no6, no7, no8, no9, no10)


# just a cherry on the cake
print("Type 'y' when ready to generate random password.")
print("Type anything else to cancel.")
if input() == "y":
    print(randgen())
else:
    pass

Result:

Type 'y' when ready to generate random password.
Type anything else to cancel.
y
2 2 7 1 3 1 6 3 0 7
None

There's the word 'None' printed.I don't want it to appear.Can anyone help?




Aucun commentaire:

Enregistrer un commentaire