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

13th Mar 2018, 4:43 PM
Josh Redmon
Josh Redmon - avatar
4 Answers
+ 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.
15th Mar 2018, 8:19 PM
Just A Rather Ridiculously Long Username
+ 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)
20th Nov 2018, 10:15 AM
Sushant Mondal
Sushant Mondal - avatar
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) ?
15th Mar 2018, 9:45 PM
Josh Redmon
Josh Redmon - avatar
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.
21st Mar 2018, 11:27 AM
Just A Rather Ridiculously Long Username