PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 30, 2022

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

 October 30, 2022     eof, module, nameerror, passwords, python     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

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

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing