1
decisão = False

class Confirmation():
    def menu(self, decisão):
        while decisão == False:
            try:
                Answer = input("Ready to play [y/n]?")
                if Answer == "y" or "n":
                    decisão = True
                    print(decisão)
                    break
            finally:
                if Answer == "y":
                    print("let's play")
                elif Answer == "n":
                    print("ok, bye")
                    exit()
                else:
                    print("Write 'y' or 'n'")
                    continue

c = Confirmation()
c.menu(decisão)

Ok so the problem is that no matter the input i use in "Answer" it always identify as "y" or "n" and turns "decisão" to true breaking the loop. Am i using the try statement wrong? because that's the only thing that comes to my mind

  • `if Answer == "y" or "n"` does not do what you think it does. Should either be `if Answer == "y" or Answer == "n"` or `if Answer in {'y', 'n'}:` [Full explanations here](https://stackoverflow.com/a/20002504/15497888) – Henry Ecker Oct 25 '21 at 01:03
  • `Answer == "y"` may be falsy, but `"n"` is always truthy. You aren't using `or` correctly according to your intentions. `or` combines two boolean expressions. You want to use `Answer == "y" or Answer == "n"` or `if Answer in {"y", "n"}`. – CherryDT Oct 25 '21 at 01:04

0 Answers0