저는 최근에 Python을 배우기 시작했고 클래스에 오류가 발생하여 "self"가 정의되지 않았습니다. 이 문제에 관해 많은 질문이 있지만 그 답변을 기반으로하는 코드로 문제를 파악할 수는 없습니다.Python 오류 - "self"가 정의되지 않았습니다.
import random
class Encrypt():
def __init__(self, master):
self.master = master
master.title("Encryption using RSA Algorithms")
x = input("Do you want to Encrypt or Decrypt?")
if x=="Encrypt":
print("Redirecting...")
else:
print("Redirecting...")
choice_1 = "Encrypt"
choice_2 = "Decrypt"
if x==choice_1:
y = input("Do you have a public key?")
if y=="Yes":
print("Redirecting...")
else:
print("Generating a key...")
print(self.publickey_generate()) #Error here that self is not defined
else:
z = input("What is your private key?")
def publickey_generate(self):
for output in range (0,1000):
public = random.randint(0, 1000)
if public <= 500:
public += public
else:
public = public - 1
이것은 제작 코드이며, 암호화 및 암호 해독 소프트웨어입니다. (주석으로 표시)이 오류는, 이런 일이 왜 모르겠어요
line 23, in Encrypt
print(self.publickey_generate(). NameError: name 'self' is not defined
입니다. 모든 입력을 부탁드립니다.
변화'수준의 암호화()'(객체) :'? – mguijarr
들여 쓰기를 수정해야합니다. – Wondercricket
''__init__'' 메소드에서 코드가 제대로 들여 쓰기되지 않은 것처럼 보입니다. – jakevdp