-2

I think that my def main() and my answer1 are having a conflict because in my code my first "answer1" makes an error and I'm not able to execute the command can someone tell me what is the problem? And what I can do?

print("Welcome to my computer game!")

playing = input("Would you like to play? ")

if playing != "yes":
    quit()

print("Nice! Let's play! ")

print("Answer true or false to these phrases.")

def main():

answer1 = input("Hugo Antunes is busy! ")

if answer1 == "false":
    print("Wrong, you should know your Hugo better!")


if answer1 == "true":
    print("Correct! ")

if any((answer1 != "true", answer1 != "false")):
    main()

answer2 = input("Next phrase. Hugo's favorite color is yellow. ")
trincot
  • 317,000
  • 35
  • 244
  • 286
  • Welcome to Stack Overflow! Please take the [tour]. There's an existing question that explains this problem in-depth, so I've closed your question under it accordingly. In the future, please start with your own research. On the other hand, it you haven't taken a Python tutorial yet, start with that. We expect you to know the language when you ask a question here. For more tips, see [ask]. – wjandrea Jul 10 '22 at 22:16

1 Answers1

0

Notice that main is a function so, you have to use indentation to make the function's scope.

Do you want something like this?

def main():

    answer1 = input("Hugo Antunes is busy! ")

    if answer1 == "false":
        print("Wrong, you should know your Hugo better!")

    if answer1 == "true":
        print("Correct! ")



    if any((answer1 != "true", answer1 != "false")):
        main()

    ...
Palinuro
  • 184
  • 1
  • 1
  • 15
  • `if any...` is not indented properly, since `answer1` wouldn't be defined. `main()` is recursive. Although, it's strange for `main()` to be recursive, and a better approach would be iterative; see [Asking the user for input until they give a valid response](/q/23294658/4518341). – wjandrea Jul 10 '22 at 22:20