0
Define & use tf_quiz() function using if/else
Python 3 problem... •tf_quiz() has 2 parameters which are both string arguments: -question: a string containing a T/F question... -correct_ans: a string indicating the correct answer, either T or F •tf_quiz() returns a string: "correct" or "incorrect" •Test tf_quiz(): create a T/F question to call tf_quiz() I keep messing this up and cannot get my code straight. Could someone please provide a simple effective answer? Thanks
4 Antworten
+ 1
I don't think this looks too hard, but I don't think I understand exactly where you are messing up. Based on assumptions I put this together.
https://code.sololearn.com/ckR7WRgo8cyc/#py
Let me know if I can clarify anything.
+ 2
The correct code is :
def tf_quiz(question, correct_ans):
if input(question).lower() == correct_ans.lower():
return("correct")
else:
return("incorrect")
quiz_eval = tf_quiz("Octopuses have eight limbs (T/F)", "t")
print("Your answer is", quiz_eval)
0
Thank you for this. I'm examining it and it's starting to make sense. as far as the end how would you add in print("Your answer is",quiz_eval) ?
0
That can also be done, and I've made it so that it is a loop that asks random questions.
https://code.sololearn.com/ckR7WRgo8cyc/#py
But it won't work here on sololearn, copy it to your IDE if you want to see it working.