I have another Python beginners question:
options =['stein', 'schere', 'papier']
class Spieler(object):
def __init__(self, nummer):
self.nummer = nummer
def abfrage(self):
print("Spieler Nr.", self.nummer)
eingabe = input("- Stein/Schere/Papier? >>>")
if eingabe.lower() in options:
print("Danke!")
# when eingabe printed out from here, always correct!
return eingabe
else:
print("Nope...")
self.abfrage() # this call is the problem
spieler1 = Spieler(1); spieler2 = Spieler(2)
wahl1 = spieler1.abfrage()
wahl2 = spieler2.abfrage()
So - the code returns a fine result "eingabe" to wahl1/2. But only if it doesn´t go through the error loop, which means the instance method calls itself again.
In these cases, "None" will be returned to wahl1/2 although if printed out from within the method the value for "eingabe" is correct.
Why?