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)

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay