How to get For loops to communicate with a While loop
<p>I need to write a program that takes the last number from the for loop ( if it exceeds a certain number) and places it in the while loop. I have left the unfinished code below.</p>

<pre><code>t=0
num=int(input("How many presents do you want to buy?: "))

for i in range(num):
   t=t+int(input("Please enter the price of a present")



while t&gt;'200':
        print("Limit Exceeded.")
        print("You need to get rid of the " #price from the previous loop
</code></pre>

<p>U need to use a list.</p>

<p>Ex</p>

<pre><code>t = 0
num=int(input("How many presents do you want to buy?: "))
prices = []
for i in range(num):
    prices.append(int(input("Please enter the price of a present")))
    t += prices[-1]
    while t &gt; 200:
        print("Limit Exceeded.")
        print("You need to get rid of the: {}".format(prices[-1]))
        t -= prices.pop()
</code></pre>

<p>AND
you are comparing wrongly:</p>

<pre><code>if t &gt; '200'
</code></pre>

<p>t is an 'int' type and you are comparing it with a string.
please correct it.</p>

<p>Hope this helps.</p>

python for-loop while-loop