Use random.randint when a program needs an integer selected between two bounds, including both endpoints. A focused exercise is a number-guessing game: choose a value from 0 through 100, repeatedly request guesses, and report whether each guess is too high, too low, or correct. section 2.2 section 2.3
import random number = random.randint(10, 30)
Import random, call random.randint with two parameters, and store the returned integer for later use. section 2.2
The upper bound is inclusive, unlike most Python ranges. Since input always returns a string, convert each guess with int before comparing it with the selected integer. section 2.3
Number-guessing loop
import random def guessing_game(): answer = random.randint(0, 100) while True: guess = int(input('Guess: ')) if guess < answer: print('Too low') elif guess > answer: print('Too high') else: print('Just right') break section 2.2 section 2.3

