Python won't break from a while True
<p>this is my code but as the title says I can not break and if I put something outside the while True and lives go below 0 nothing happens.    </p>

<pre><code>from random import randint
    import sys
    value = int(randint(1,10))
    lives = int(5)
    userinp = int(0)
    if lives == 0:
        print("no lives :(")
    while True:
        if lives != 0:
            print(value)
            print("You currently have: ", lives, " lives left")
            userinp = input("Please enter a number from 1 to 10: ")
            if int(userinp) == int(value):
                print("Well done you wn :D")
                sys.exit()
            elif int(userinp) &gt; int(value):
                print("Your guess was too high please guess again")
                lives = lives - 1
            elif int(userinp) &lt; int(value):
                print("Your guess was too low please guess again")
                lives = lives - 1
    if lives == 0:
        print("this")
</code></pre>

<p>Your loop essentially looks like:</p>

<pre><code>while True:
    if lives != 0:
        # do stuff with lives
</code></pre>

<p>This is an infinite loop. The loop wont break even if <code>lives == 0</code>, because this condition is tested as part of the loop block, not as the loop condition.
You should simply do :</p>

<pre><code>while lives != 0:
    # do stuff with lives
</code></pre>

<p>Or even <code>while lives &gt; 0:</code> in case you manage to loose several lives during 1 loop iteration (doesn't seem to be possible here but better safe than sorry).</p>

<p>And since you seem to want to learn Python, there are a few other things you may want to learn and improve also:</p>

<p>No need to convert integers to integers here:</p>

<pre><code>value = int(randint(1,10))
lives = int(5)
userinp = int(0)
</code></pre>

<p>Numbers like <code>5</code> and <code>0</code>, and <code>randint(1,10)</code> are integers by themselves. <code>"5"</code> and <code>"0"</code> are strings containing a number as single character and would need to be converted before being compared to integers, but it is not needed here. randint() returns integers.</p>

<p>This is dead code since you have set  <code>lives</code> to <code>5</code> 2 lines above and not modified it afterwards:</p>

<pre><code>if lives == 0:
    print("no lives :(")
</code></pre>

<p>You should check if the user actually inputs a valid integer convertible value instead of an arbitrary string: (<code>continue</code> will skip to the next loop iteration, so it will ask the user for input again without decrementing <code>lives</code></p>

<pre><code>userinp = input("Please enter a number from 1 to 10: ")
if not userinp.isnumeric(): continue
</code></pre>

<p>No need to convert your already integer <code>value</code> to an integer again and again and AGAIN:</p>

<pre><code>if int(userinp) == int(value):

elif int(userinp) &gt; int(value):

elif int(userinp) &lt; int(value):
</code></pre>

<p>Avoid using <code>sys.exit()</code>, you may just <code>break</code> instead (to get out of the loop and continue.</p>

<p>And finally, Python has handy <code>-=, +=, *=, /=</code> operators, so you can write <code>lives -= 1</code> instead of <code>lives = lives - 1</code></p>

python