0

I'm new to python and I'm kind of stuck. When I run my program, I get this

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

I don't understand what I am doing wrong, can someone please explain to me what that error message means? Thanks.

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

1 Answers1

0

Looks like you wanted to keep your while loop inside your class :

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()
Claude
  • 11
  • 5