The program below is just a high/low numbers game. One of the 4 criteria is having an error check to make sure the lower variable is in fact lower than the upper variable.
I've tried implementing it a few different ways to no success. I keep receiving a ValueError and I'm pretty certain it's because if I enter 10 as the "lower" variable and 1 as the "upper" variable, randint
is trying to call randint(10, 1)
instead of prompting the user an error and to reenter the numbers. I've tried a separate loop and if
statements.
import random
seedVal = int(input('What seed should be used? '))
random.seed(seedVal)
lower = int(input('Enter lower bound. '))
upper = int(input('Enter upper bound. '))
answer = random.randint(lower, upper)
while True:
guess = int(input('What is your guess? '))
if guess < lower or guess > upper:
print('Please enter a guess between lower bound and higher bound.')
elif guess == answer:
print('You got it!')
break
elif guess > answer:
print('Nope, too high.')
else:
print('Nope, too low.')