ich habe ein kleines Lottoprogramm geschrieben und würde gerne Folgendes wissen:
1. Wie lässt es sich kürzen?
2. Wie kann ich verhindern, dass ein bloßes "Enter" das Programm abbricht und
3. wie kann ich verhindern, dass Kommazahlen akzeptiert werden?
Vielen Dank im Voraus!!
Code: Alles auswählen
# lotto
from random import*
def lotto():
richtige=0
print "Tippe 6 aus 49!"
tipp1 = input("Tipp1: ")
while tipp1>49 or tipp1<1:
tipp1 = input("Die Zahl muss zwischen 1 und 49 liegen! Tipp1: ")
tipp2 = input("Tipp2: ")
while tipp2>49 or tipp2<1:
tipp2 = input("Die Zahl muss zwischen 1 und 49 liegen! Tipp2: ")
while tipp2==tipp1:
tipp2=input ("Der Tipp kam schon vor. Nimm eine andere Zahl: ")
tipp3 = input("Tipp3: ")
while tipp3>49 or tipp3<1:
tipp3 = input("Die Zahl muss zwischen 1 und 49 liegen! Tipp3: ")
while tipp3==tipp2 or tipp3==tipp1:
tipp3=input ("Der Tipp kam schon vor. Nimm eine andere Zahl: ")
tipp4 = input("Tipp4: ")
while tipp4>49 or tipp4<1:
tipp4 = input("Die Zahl muss zwischen 1 und 49 liegen! Tipp4: ")
while tipp4==tipp3 or tipp4==tipp2 or tipp4==tipp1:
tipp4=input ("Der Tipp kam schon vor. Nimm eine andere Zahl: ")
tipp5 = input("Tipp5: ")
while tipp5>49 or tipp5<1:
tipp5 = input("Die Zahl muss zwischen 1 und 49 liegen! Tipp5: ")
while tipp5==tipp4 or tipp5==tipp3 or tipp5==tipp2 or tipp5==tipp1:
tipp5=input ("Der Tipp kam schon vor. Nimm eine andere Zahl: ")
tipp6 = input("Tipp6: ")
while tipp6>49 or tipp6<1:
tipp6 = input("Die Zahl muss zwischen 1 und 49 liegen! Tipp6: ")
while tipp6==tipp5 or tipp6==tipp4 or tipp6==tipp3 or tipp6==tipp2 or tipp6==tipp1:
tipp6=input ("Der Tipp kam schon vor. Nimm eine andere Zahl: ")
zahl1 = int(random()*49+1)
zahl2 = int(random()*49+1)
zahl3 = int(random()*49+1)
zahl4 = int(random()*49+1)
zahl5 = int(random()*49+1)
zahl6 = int(random()*49+1)
while zahl2==zahl1:
zahl2 = int(random()*49+1)
while zahl3==zahl2 or zahl3==zahl1:
zahl3 = int(random()*49+1)
while zahl4==zahl3 or zahl4==zahl2 or zahl4==zahl1:
zahl4 = int(random()*49+1)
while zahl5==zahl4 or zahl5==zahl3 or zahl5==zahl2 or zahl5==zahl1:
zahl5 = int(random()*49+1)
while zahl6==zahl5 or zahl6==zahl4 or zahl6==zahl3 or zahl6==zahl2 or zahl6==zahl1:
zahl6 = int(random()*49+1)
print "Ziehung: ",zahl1,
print zahl2,
print zahl3,
print zahl4,
print zahl5,
print zahl6
ziehung=[zahl1,zahl2,zahl3,zahl4,zahl5,zahl6];
ziehung.sort();
print "Sortierte Liste:",ziehung
if tipp1==zahl1 or tipp1==zahl2 or tipp1==zahl3 or tipp1==zahl4 or tipp1==zahl5 or tipp1==zahl6:
richtige=richtige+1
if tipp2==zahl1 or tipp2==zahl2 or tipp2==zahl3 or tipp2==zahl4 or tipp2==zahl5 or tipp2==zahl6:
richtige=richtige+1
if tipp3==zahl1 or tipp3==zahl2 or tipp3==zahl3 or tipp3==zahl4 or tipp3==zahl5 or tipp3==zahl6:
richtige=richtige+1
if tipp4==zahl1 or tipp4==zahl2 or tipp4==zahl3 or tipp4==zahl4 or tipp4==zahl5 or tipp4==zahl6:
richtige=richtige+1
if tipp5==zahl1 or tipp5==zahl2 or tipp5==zahl3 or tipp5==zahl4 or tipp5==zahl5 or tipp5==zahl6:
richtige=richtige+1
if tipp6==zahl1 or tipp6==zahl2 or tipp6==zahl3 or tipp6==zahl4 or tipp6==zahl5 or tipp6==zahl6:
richtige=richtige+1
print
print "Du hast",richtige,"Richtige!"