Reputation: 11
I am making a number guessing game, and I have created a random integer using random.randint(1,100). I would like to create a range of ten higher and ten lower than the number created, that way if the number guessed by the player is withing ten of the randomly generated number, I can say higher or lower. I tried creating a range of 10 and creating variables of Overguess and Underguess, but I cannot add and integer and a list. Is there a way to create that range?
Upvotes: 1
Views: 33
Reputation: 58
import random
magic_number = random.randint(1,100)
number = int(input("Number : "))
for low in range (magic_number-10, magic_number+1):
if number == low:
print("Low!")
for high in range (magic_number, magic_number+11):
if number == high:
print("High!")
print("Magic Number :", magic_number)
Like This?
Upvotes: 1