VisuAlg Web

Sorteios (random.randint)

Em Python, sorteios inteiros são feitos com random.randint(inicio, fim) .

Em Python, sorteios inteiros são feitos com random.randint(inicio, fim).

Exemplo de códigoPython


import random

drawn_number = random.randint(0, 10)  # Draws from 0 to 10
print("The machine drew number: ", drawn_number)
Exemplo de códigoPython


import random

# randint(1, 6) already generates from 1 to 6
d6_roll = random.randint(1, 6)

print("You rolled the dice...")
print("It landed on: ", d6_roll)