Hallo meine Frage wo liegt der Fehler bei diesem kleinen simplen Spiel?
# Zufallsgenerator
import random
random.seed()
# Werte und Berechnung
a= random.randint (0,20)
b= random.randint (0,20)
c= a + b
print 'Die Aufgabe:', a, '+', b
# Schleife mit for
for i in 1, 2 , 3, 4:
# Eingabe
print 'Bitte eine Zahl eingeben:'
z= input()
zahl= int(z)
# Verzweigung
if zahl== c:
print zahl, 'ist richtig'
# Abbruch der Schleife
break
else:
print zahl, 'ist falsch'
# Ende
print 'Ergebnis:', c
Fehlersuche Spiel mitfor-Schleife und Abbruch
- __blackjack__
- User
- Beiträge: 14322
- Registriert: Samstag 2. Juni 2018, 10:21
- Wohnort: 127.0.0.1
- Kontaktdaten:
@mortench: Gute Frage. Welche Fehlermeldung bekommst Du denn? Oder wo verhält sich das nicht so wie Du es erwartest?
„Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.“ — Brian W. Kernighan
- __blackjack__
- User
- Beiträge: 14322
- Registriert: Samstag 2. Juni 2018, 10:21
- Wohnort: 127.0.0.1
- Kontaktdaten:
@mortench: Der `random.seed()`-Aufruf ist unnötig. Und `input()` solltest Du in Python 2 nicht verwenden. Da nimmt man `raw_input()`. Andererseits könntest Du überlegen gleich Python 3 zu verwenden.
„Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.“ — Brian W. Kernighan
