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