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>A <code>while True</code> is an infinite loop, consuming 100% of all CPU cycles and will never break - since a <code>while &lt;condition&gt;</code> only ends when the condition becomes <code>False</code>, but that can never be, because it is always <code>True</code>!</p>

<p>Try not fighting the nature of your loop: </p>

<pre><code>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:  # indent condition to fall within the loop
        print("this")
    if lives &lt; 0:  # add an extra case to handle what you want
        break
</code></pre>

python