#create function with two paramaters
def quiz_item(question,solution):
#ask question and get input
question = input("The blue whale is the biggest animal to have ever lived. ")
solution = "T"
#while loop
while question != solution:
question = input("INCORECT try again: The blue whale is the biggest animal to have ever lived. ")
#if answer is == to solution print correct
if question == solution:
print("That is correct!")
break
quiz_item(question,solution)
#output says solution not defined
How should I call the function for the code to run
CodePudding user response:
Looks like you're still learning. That's nice!
Very well. You'll have multiple solutions but i'll try to explain the simplest of them.
Simplest solution: You can define the function without any arguments. Like this:
#create function with two paramaters
def quiz_item():
#ask question and get input
question = input("The blue whale is the biggest animal to have ever lived. ")
solution = "T"
#while loop
while question != solution:
question = input("INCORECT try again: The blue whale is the biggest animal to have ever lived. ")
#if answer is == to solution print correct
if question == solution:
print("That is correct!")
break
quiz_item()
CodePudding user response:
You already define the variables 'question' and 'solution' inside the function, so no need to pass them as parameters when calling to the function.
Your code should look like this:
#create function with two paramaters
def quiz_item():
# ask question and get input
question = input("The blue whale is the biggest animal to have ever lived. ")
solution = "T"
# while loop
while question != solution:
question = input("INCORECT try again: The blue whale is the biggest animal to have ever lived. ")
#if answer is == to solution print correct
if question == solution:
print("That is correct!")
break
if __name__ == '__main__':
quiz_item()