如何修复此 python 程序中的 EoF 错误?

How to fix the EoF error in this python program?

是python-3中的密码生成程序。在我们想要输入该密码作为输入后,它将自动生成随机字符中的密码。如果它是正确的,则授予访问权限...但是我在 "if statement" 中有 eof 错误,无论给出什么输入,它都会打印被拒绝​​的选项。帮忙解决我的代码

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")

您需要使用空字符串而不是 space 初始化 pas

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")