Python loop ask
<p>Can someone help me how do i display both food and drink if i answered yes?</p>

<p>example:</p>

<p>choose:1</p>

<p>you have entered food</p>

<p>Do you want to select another?(Y/N):y</p>

<p>choose:2</p>

<p>Do you want to select another?(Y/N):n</p>

<p>selected:</p>

<p>food</p>

<p>drink</p>

<p>thanks in advance</p>

<pre><code>    answer="Y"
    while(answer=="Y"):       
      print("1-food")
      print("2-drink")
      opt=int(input("Choose:"))`
      if(opt==1):` 
          print("You have selected food")
      if(op==2):
          print("You have selected drink"):
     answer=input("Do you want to select another?(Y/N)").upper()
</code></pre>

<pre><code>food = False
drink = False    
answer="Y"
    while(answer=="Y"):       
      print("1-food")
      print("2-drink")
      opt=int(input("Choose:"))
      if(opt==1): 
          print("You have selected food")
          food = True
      if(op==2):
          print("You have selected drink"):
          drink = True
     answer=input("Do you want to select another?(Y/N)").upper()
if food: print "food"
if drink: print "drink"
</code></pre>

<p>All you need to do is add two variables <code>food</code> and <code>drink</code> and if you selected the relevant option then you set it to <code>True</code>. Then at the end of your <code>while</code> loop you simply test to see if they are set.</p>

python loops while-loop