I am new to Python and am trying to make this interactive guessing game using Python 3. At ANY point in the game, if user just presses "Enter" without any input, it crashes to "ValueError: invalid literal for int() with base 10: ''" What do I add here?
Just to reiterate, I am new to programming. I am trying to code this entirely only using concepts I have learned so far, so everything is fairly basic.
# 'h' is highest value in range. 'a' is randomly generated value in the range. 'u' is user input
import random
h = 10
a = random.randint(1,h)
u = int(input("Please choose a number between 1 and %d. You can exit the game by pressing 0 anytime: " %(h)))
while u != a:
if 0 < u < a:
print("Please guess higher.")
u = int(input())
elif a < u < h:
print("Please guess lower.")
u = int(input())
elif u > h:
u = int(input("Whoa! Out of range, please choose within 1 and %d!" %(h)))
elif u == 0:
print("Thanks for playing. Bye!!")
break
# I was hoping to get the below response when user just presses "enter" key, without input
else:
print("You have to enter a number.")
u = int(input())
if u == a:
print("Well done! You got it right.")
int(input()). Instead, first save the result ofinput()into a variable, and then check if it's empty, ..