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("Not an integer! Try again.")
continue
else:
return userInput
break
#ranges must be integers
min_range = int(inputNumber("Please insert the min range: "))
temp_range = int(inputNumber("Please insert the max range: "))
#max range must be bigger than min
while min_range >= temp_range:
temp_range = int(inputNumber("Please insert a max range which is smaller than min range!: ")) + 1
max_range = temp_range
random_number = random.randint(min_range, max_range)
guess = int(input("Please enter your guess: "))
counter = 1; # you guessed once already
while guess != random_number: # 1 guess incorrect
print(f"{random_number} is the random number")# to see for myself which is the random numb
if min_range < guess < max_range: # WITHIN THE RANGE
if random_number - random_number / 12 < guess-random_number < random_number + random_number / 12: # 3 super hot
print("Please try again, you are super hot!")
elif random_number - random_number / 8 < guess-random_number < random_number + random_number / 8: # 3 hot
print("Please try again, you are hot!")
elif guess < random_number - random_number / 2 or guess-random_number > random_number + random_number / 2: # 3 cold
print("Please try again, you are cold!")
else: # OUTSIDE RANGE
print("You are outside the range, try again!")
guess = int(input())
counter += 1
if guess == random_number: # guess correct
print(f"Congratulations, you guessed correctly in {counter} tries!")
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 (: