-1

I am having a problem in my python code. I am a beginner so this in a really simple ask. So I only have some months experience(4 months). I am making a project in which there are QnA(s) I am having problem with 2 things. First: I am not able to call these functions:

def questions() 

def question2()

Second problem: I want to make options for the questions for E.G:

def question():


    Q1 = input("Who is the lord of a random place")
    if Q1 == ["Lofi", "Loafer", "Lofe"]:
        print('Correct answer!!')
    else:
        print('Wrong answer!! The correct answer is LOFI!!')

I am not sure what operator or keyword to use to do this. Please help, Here is the Code:

def question():


    Q1 = input("Who is the lord of a random place")
    if Q1 == ["Lofi", "Loafer", "Lofe"]:
        print('Correct anwer!!')
    else:
        print('Wrong answer!! The correct answer is LOFI!!')
    question() 
def question2():
    Q2 = input("Who is the most trustful person in the world?")
    if Q2 == ["Lofi", "Annu", "scoob"]:
        print("Correct answer!! U WIN!!!!")
    else:
        print("WRONG ANSWER!!")
    question2()

 
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Lofi
  • 7
  • 3

2 Answers2

0

How are you? To call a function you should do this => myfunction()

You don't need to put a word def before your function when you want to call your function. To call functions try this code :

questions()
question2()

For your second question I don't understand that

0
  1. You need to indent the program correctly . Call to the functions question() and question2() needs to be in the root indent

  2. You can either check the string is present in a list by using "in" keyword as in question function , or use keyword "any" as in the question2 function

    def question():
      Q1 = input("Who is the lord of a random place")
      if Q1 in ["Lofi", "Loafer", "Lofe"]:
         print('Correct anwer!!')
      else:
         print('Wrong answer!! The correct answer is LOFI!!')
    
    
    def question2():
      Q2 = input("Who is the most trustful person in the world?")
      Ans =  ["Lofi", "Loafer", "Lofe"]
      if any(Q2 in item for item in Ans):
         print("Correct answer!! U WIN!!!!")
      else:
         print("WRONG ANSWER!!")
    
    question() 
    
    question2()
    
Vineesh Vijayan
  • 570
  • 4
  • 15