0
Warum gibt dieser Code immer die erste Bedingung zurück, auch wenn die Eingabe -1 oder -2 ist und die if-Anweisung nur 0 und höher annehmen sollte?Warum wird die erste Bedingung immer zurückgegeben, auch wenn sie außerhalb des Parameters liegt?
european_floor = raw_input("Which floor of a Parisian hotel would you like to stay in tonight?")
us_floor = int(european_floor) + 1
lower_us_floor = int(european_floor) - 1
if european_floor > -1:
print ("For floor " + str(european_floor) + " in Paris, the equivalent floor in New York would be floor " + str(us_floor) + "!")
elif european_floor < -1:
print ("For floor " + str(european_floor) + " in Paris, the equivalent floor in New York would be floor " + str(lower_us_floor) + "!")
else:
print ("For floor " + str(european_floor) + " in Paris, the equivalent floor in New York would be the basement!")
Sie wenden if/elif an den european_floor an, der eine Zeichenfolge ist. Weil du es nur in us_floor und lower_us_floor variables in integer umwandelst ... versuch dies: european_floor = int (raw_input ("In welchem Stockwerk eines Pariser Hotels möchtest du heute Abend übernachten?")) –