Einzelnen Beitrag anzeigen
Alt 21.05.08, 03:47   #18 (permalink)
Ook!
 
Registriert seit: 21.04.08
Ook! Leistung: Facit NTK
Likes: 0
Standard

Hallo!

Meine Python Lösung

Code:
#!/usr/bin/env python2.5

import random

def userNums():
    userList = []
    while(len(userList) < 6):
        num = int(raw_input(("%d. Zahl: " % (len(userList)+1))))
        if userList.count(num) > 0:
            print "Zahl schon vorhanden!"
        elif num < 1 or num > 49:
            print "Nur Zahlen zwischen 1 und 49!"
        else:
            userList.append(int(num))
    userList.sort()
    return userList

def lottoNums():   
    lottoList = [ i for i in range(1,50) ] 
    while(len(lottoList) > 6):
        lottoList.remove(random.choice(lottoList))
    lottoList.sort()
    return lottoList
        
def evaluate(userList, lottoList):
    return filter(lambda x: [ i for i in userList if i==x ], lottoList)

def sixHits(userList):
    sixList = []
    count = 0
    while userList != sixList:
        sixList = lottoNums()
        count += 1
    return count
        

print "*** LOTTO ***\n*************\n"

print "Geben Sie Ihre sechs Zahlen ein"
userList = userNums()

print "\nDie Lotto-Zahlen wurden gezogen..."
lottoList = lottoNums()

matches = evaluate(userList, lottoList)
print "Gezogene Zahlen: %s " % (lottoList)
print "Ihre Zahlen: %s" % (userList)
print "Sie haben %d Richtige: %s" % ((len(matches)), matches)

print "\nVersuche fuer 6 Richtige werden ausgewertet"
count = sixHits(userList)
print "Sie haetten %d Versuche gebraucht!" % (count)
print "Das entspricht einer Chance von %s%s!" % (1.0/count*100, "%")
Gruß
Felix
Ook! ist offline   Mit Zitat antworten
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61