我是python的新手,我有点卡住了。当我运行我的程序时,我得到了这个
"Traceback (most recent call last):
File "C:/Users/Dell/Documents/Code/junk.py", line 1, in <module>
class E:
File "C:/Users/Dell/Documents/Code/junk.py", line 27, in E
YN_prompt()
TypeError: YN_prompt() missing 1 required positional argument: 'self'
我不明白我做错了什么,有人可以向我解释一下这个错误信息的含义吗?感谢。
class E:
import random
import time
thing = 1
cookie = random.randrange(4)
def YN_prompt(self):
ugly = 1
while ugly == 1:
yn = input("\n Go again? y/n \n")
if yn == ("y"):
continue
elif yn == ("n"):
quit()
else:
print("ILLEGAL VALUE, CHOOSING ANOTER")
time.sleep(0.2)
continue
while thing == 1:
if cookie == 0:
print("hi")
YN_prompt()
elif cookie == 1:
print("no")
YN_prompt()
elif cookie == 2:
print("why")
YN_prompt()
elif cookie == 3:
print("when")
YN_prompt()
elif cookie == 4:
print("who")
YN_prompt()
答案 0 :(得分:0)
看起来你想在你的班级中保留你的while循环:
class E:
import random
import time
thing = 1
cookie = random.randrange(4)
def YN_prompt(self):
ugly = 1
while ugly == 1:
yn = input("\n Go again? y/n \n")
if yn == ("y"):
continue
elif yn == ("n"):
quit()
else:
print("ILLEGAL VALUE, CHOOSING ANOTER")
time.sleep(0.2)
continue
while thing == 1:
if cookie == 0:
print("hi")
YN_prompt()
elif cookie == 1:
print("no")
YN_prompt()
elif cookie == 2:
print("why")
YN_prompt()
elif cookie == 3:
print("when")
YN_prompt()
elif cookie == 4:
print("who")
YN_prompt()