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

udanielnogueira

Daniel Nogueira

Posted on November 5, 2022

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
💖 💪 🙅 🚩
udanielnogueira
Daniel Nogueira

Posted on November 5, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related