The random module generates pseudorandom values and supports random selection. Its randint function returns an integer between two bounds, including both endpoints. section 2.2 section 2.3
Number guessing game
Use the module to choose a hidden number, then combine input, integer conversion, comparisons, and a loop: import random 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 Remember that randint(0, 100) can return 0 or 100. The input function returns a string, so convert the response before comparing it with the integer answer. section 2.2 section 2.3
When applying the module, keep these details in view:
- Import random before calling random.randint. section 2.3
- Treat the upper randint bound as inclusive, unlike many Python ranges. section 2.3
- Explore other random functions for choosing elements from Python sequences. section 2.3



