DEV Community

Cover image for Let's Make the Computer Think of a Number with Python
Daniel Nogueira
Daniel Nogueira

Posted on

Let's Make the Computer Think of a Number with Python

A practical way of doing that's using the random library. Let's import it:

import random
Enter fullscreen mode Exit fullscreen mode

Among the random methods, there is the randint method, that returns an integer value within a specified range.

random.randint(0,10)
Enter fullscreen mode Exit fullscreen mode

Just use a variable to store the value the function will return and that's it, we can display the value the computer thought.

x = random.randint(0,10)
print(x)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)