Python 3.2 how to set correct and incorrect answer on questions inside 2 lists
<p>I am making 2 sets of question, first set (list1) is all yes and second (list2) is all no 10 questions each then I used random.choice to randomly pick a question from the 2 sets. I want to make an output of "correct" whenever random.choice picks a question from list 1 when the user answered "Y" same with list2 if the user answered "N". Here is my code:</p>

<pre><code>import random


Count = 0

list1 = ['1+1=2?','2+2=4?','3+3=6?','4+4=8?','5+5=10?','15+15=30?','16+16=32?','17+17=34?','18+18=36?','19+19=38?']
list2 = list2 = ['20+20=10?','6+6=2?','7+7=11?','8+8=32?','9+9=21?','10+10=0?','11+11=4?','12+12=12?','13+13=25?','14+14=13?']
list = list1 + list2

while(Count &lt; 5):
    print(random.choice(list))
    Answer = input("Answer: ").upper()
    Count = Count+1
    if(list == list1):
       if(Answer == "Y"):
          print("Correct")
       else:
          print("Incorrect")
    if(list == list2):
       if(Answer == "N"):
          print("Correct")
       else:
          print("Incorrect")
</code></pre>

<p>I cannot figure out how to output the correct and incorrect statement. Any help would be truly appreciated.</p>

<p>Rather than searching the two lists for the chosen question it's simpler to randomly choose a list and then choose a question from that list. This approach will have the same probability of choosing a given question as your approach as long as both lists have the same length.</p>

<p>We can still combine the two lists into a single data structure; the code below combines them into a dictionary, with the answer as the key.</p>

<pre><code>from random import choice

questions = {
    'Y': [
        '1+1=2?', '2+2=4?', '3+3=6?', '4+4=8?', '5+5=10?', '15+15=30?', 
        '16+16=32?', '17+17=34?', '18+18=36?', '19+19=38?',
    ],
    'N': [
        '20+20=10?', '6+6=2?', '7+7=11?', '8+8=32?', '9+9=21?', '10+10=0?', 
        '11+11=4?', '12+12=12?', '13+13=25?', '14+14=13?',
    ],
}

for _ in range(5):
    key = choice('YN')
    print(choice(questions[key]))
    answer = input("Answer: ").upper()
    if answer == key:
        print("Correct")
    else:
        print("Incorrect")
</code></pre>

<p><strong>typical output</strong></p>

<pre><code>14+14=13?
Answer: N
Correct
19+19=38?
Answer: n
Incorrect
11+11=4?
Answer: Y
Incorrect
3+3=6?
Answer: y 
Correct
13+13=25?
Answer: n
Correct
</code></pre>

<p>We can make the code more compact by replacing the <code>if...else</code> block with this:</p>

<pre><code>print(("Incorrect", "Correct")[answer == key]) 
</code></pre>

<p>That works because <code>False</code> has a numeric value of 0 and <code>True</code> has a numeric value of 1.</p>

python python-3.x