Sunday, October 30, 2022

[FIXED] How to fix the EoF error in this python program?

Issue

It is password generator program in python-3. It will auto generate the password in random char, after we want enter that password as input. If it is correct access is granted otherwise... But i have eof error in "if statement" it prints the denied option whatever input is given. Help to solve my code

import random
char = 'abcdefghijklmnopqrstuvwxyz1234567890'
length = input('password lenght?')
len = int(length)
for p in range(1):
    pas = ' '
    for c in range(len):
         pas += random.choice(char)
         g = pas
    print (g)
code = input("Enter password :")

if g == code:
    print("Access Granted")
else:
    print("Access Denied")

Solution

You need to initialize pas with empty string not with a space.

import random
char = 'abcdefghijklmnopqrstuvwxyz1234567890'
length = input('password lenght?')
len = int(length)
for p in range(1):
    pas = ''
    for c in range(len):
         pas += random.choice(char)
    g = pas
    print (g)
code = input("Enter password :")

if g == code:
    print("Access Granted")
else:
    print("Access Denied")


Answered By - xashru
Answer Checked By - Katrina (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.