Lomax Miller
Lomax Miller

Reputation: 11

How can I create a range from a random integer?

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

Answers (1)

Hilmi Azizi
Hilmi Azizi

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

Related Questions