Skip to content

Free preview: 16 of 43 conceptsUnlock all

Your progress is not saved. Create a free account to keep it.

Number Guessing Game

Generating a Random Integer

Use the random module for your guessing game

To generate a random integer for a number guessing game, you can use the randint function inside Python's random module.

First, import the module, and then call random.randint() with a range:

import random
number = random.randint(10, 30)

In this example, number will contain a random integer from 10 up to and including 30. Notice that the maximum number in random.randint is inclusive.

Python Workout

Course map

Choose what to study. The order is a suggestion.

Rate Python Syntax Practice