DEV Community

Cover image for Vamos Fazer o Computador Pensar em um Número com Python
Daniel Nogueira
Daniel Nogueira

Posted on • Edited on

4

Vamos Fazer o Computador Pensar em um Número com Python

Uma maneira prática de fazer isso é usando a biblioteca random. Vamos importá-la:

import random
Enter fullscreen mode Exit fullscreen mode

Dentre os métodos da random, existe o método randint, cujo objetivo é retornar um valor inteiro dentro de uma faixa especificada.

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

Basta usar uma variável para armazenar o valor que a função irá retornar e pronto, podemos exibir o valor em que o computador pensou.

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

Top comments (0)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay