Is there a better way to condense the while loop? I have been trying to write a number guessing game and I am trying to condense the second while loop when guess =! random_number. I can't figure out if there is any better way to shorten the code but to still achieve the same result. I wonder if someone is able to help me out.  If there's anything else which is redundant or not efficient in my code or how i could code it better please criticize the hell out me my work!
import random

def inputNumber(message):
    while True:
        try:
            userInput = int(input(message))
        except ValueError:
            print(&quot;Not an integer! Try again.&quot;)
            continue
        else:
            return userInput
            break

#ranges must be integers
min_range = int(inputNumber(&quot;Please insert the min range: &quot;))
temp_range = int(inputNumber(&quot;Please insert the max range: &quot;))

#max range must be bigger than min
while min_range &gt;= temp_range:
    temp_range = int(inputNumber(&quot;Please insert a max range which is smaller than min range!: &quot;)) + 1

max_range = temp_range

random_number = random.randint(min_range, max_range)

guess = int(input(&quot;Please enter your guess: &quot;))
counter = 1;  # you guessed once already
while guess != random_number:  # 1 guess incorrect
    print(f&quot;{random_number} is the random number&quot;)# to see for myself which is the random numb
    if min_range &lt; guess &lt; max_range:  # WITHIN THE RANGE
        if random_number - random_number / 12 &lt; guess-random_number &lt; random_number + random_number / 12:  # 3 super hot
            print(&quot;Please try again, you are super hot!&quot;)
        elif random_number - random_number / 8 &lt; guess-random_number &lt; random_number + random_number / 8:  # 3 hot
            print(&quot;Please try again, you are hot!&quot;)
        elif guess &lt; random_number - random_number / 2 or guess-random_number &gt; random_number + random_number / 2:  # 3 cold
            print(&quot;Please try again, you are cold!&quot;)

    else:  # OUTSIDE RANGE
        print(&quot;You are outside the range, try again!&quot;)
    guess = int(input())
    counter += 1
if guess == random_number:  # guess correct
    print(f&quot;Congratulations, you guessed correctly in {counter} tries!&quot;)

edit: thanks you all so much for taking the time to review my code, i will try to improve on the noted points, much appreciated (:
Miscellaneous notes:

you don't need a break after a return
you could (attempt to) return directly from the input; &quot;except&quot; will still catch and cycle errors
inputNumber() explicitly returns an integer; no need to cast again.
temp_range isn't really needed - you can just use max_range, no loss to readability.
no need to add one to max_range (in the validation loop) - randint() includes the top limit.
random_number is an unhelpful variable name - I've called this target
using inputNumber() for the guess also seems sensible.
guess should be checked against the inclusive range - min and max are possible values.
personally I think the temperature categories should reflect the size of the range, rather than the size of the chosen number... however
your calculation is wrong anyway; you are testing the difference between guess and target so you should test against the small fraction of target, not target reduced by a fraction (or should just check guess against the numbers you calculate).
the &quot;hot&quot; range (outside &quot;super hot&quot;) is actually smaller than the &quot;super hot&quot; range - I adjusted this out to 1/4 of target
after correction, there's a range that gets no message, which can be covered in an else clause. I reordered so all tests are for &quot;in this range&quot; and the else covers the &quot;cold&quot; option.

To condense the message selection, you could set up a list of boundaries changing from one condition to another, and step through (or search) to find the applicable message. However I'm not sure that's a lot clearer in this case.
With updates reflecting most of these:
import random
CHEATING = True

def inputNumber(message):
    while True:
        try:
            return int(input(message))
        except ValueError:
            print(&quot;Not an integer! Try again.&quot;)

#ranges must be integers
min_range = inputNumber(&quot;Please insert the min range: &quot;)
max_range = inputNumber(&quot;Please insert the max range: &quot;)

#max range must be bigger than min
while min_range &gt;= max_range:
    max_range = inputNumber(&quot;Please insert a max range which is bigger than min range!: &quot;)

target = random.randint(min_range, max_range)

guess = inputNumber(&quot;Please enter your guess: &quot;)
counter = 1;  # you guessed once already
while guess != target:  # 1 guess incorrect
    if CHEATING: print(f&quot;{target} is the random number&quot;)# to see for myself which is the random numb
    if min_range &lt;= guess &lt;= max_range:  # WITHIN THE RANGE
        if  -target / 12 &lt; guess-target &lt; target / 12:  # 3 super hot
            print(&quot;Please try again, you are super hot!&quot;)
        elif  -target / 4 &lt; guess-target &lt; target / 4:  # 3 hot
            print(&quot;Please try again, you are hot!&quot;)
        elif -target / 2 &lt; guess-target &lt; target / 2:   # a bit meh
            print(&quot;Not great, not terrible - please try again&quot;)
        else:                                           # 3 cold
            print(&quot;Please try again, you are cold!&quot;)

    else:  # OUTSIDE RANGE
        print(&quot;You are outside the range, try again!&quot;)
    guess = inputNumber(&quot;Next guess? &quot;)
    counter += 1
if guess == target:  # guess correct
    print(f&quot;Congratulations, you guessed correctly in {counter} tries!&quot;)```

PS: &quot;please criticize the hell out my work&quot; is an excellent attitude, if you have the fortitude for it, and a great way to learn.