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>My solution is slightly different!
Save the equations in the list with the double == and after do in this way:</p>

<pre><code>import random

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 = ['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']
lst = list1 + list2

for _ in range(5):
    value = random.choice(lst)
    print(value)
    Answer = input("Answer: ").upper()
    state = eval(value)
    if(Answer == "Y" and state is True) or (Answer == "N" and state is False):
            print("Correct")
    else:
            print("Incorrect")
</code></pre>

<p>The eval function take in input one string containing the operation and solve it. In this case it's a logical operation so it will return you True or False.
Try the eval function on the Python shell if you don't know it.</p>

<p>In this way if you want you could use only one list.</p>

<p>In that case:</p>

<pre><code>import random

lst = ['1+1==2','2+2==4','3+2==6','4+3==8','5+5==10','15+8==30','16+16==32','17+22==34','18+30==36','19+19==38']

for _ in range(5):
    value = random.choice(lst)
    print(value)
    Answer = input("Answer: ").upper()
    state = eval(value)
    if(Answer == "Y" and state is True) or (Answer == "N" and state is False):
            print("Correct")
    else:
            print("Incorrect")
</code></pre>

python python-3.x