Ministério da Educação
Brasil um país de todos
Personal tools
Navigation
Log in


Forgot your password?
 
Document Actions

lista5ex4.py

by Cicero Garrozi last modified 2015-05-08 05:45

Click here to get the file

Size 1 kB - File type text/python-source

File contents

from random import randint
from random import shuffle

#este trecho eh identico ao shuffle:
lista = [None]*10
pos = 0
while None in lista:
    numero = randint(0, 9)
    if numero not in lista:
        lista[pos] = numero
        pos += 1
#outra maneira:
#suffle(lista)

dezenas = range(6)
unidades = range(10)
sorteados = []
i = 0
while i < 6: #sorteando os numeros da mega sena:
    shuffle(dezenas)
    shuffle(unidades)
    #sorteando a unidade e a dezena:
    u = unidades[randint(0,9)]
    d = dezenas[randint(0,5)]
    if u == 0 and d == 0:
        d = 6
    numero = int("%s%s"%(d,u))
    if numero not in sorteados:
        sorteados.append(numero)
        i += 1

print "numeros sorteados: "," ".join([str(k) for k in sorteados])

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: