Ich programmiere ein Spiel, um zu versuchen, meine Fähigkeiten in Python zu verbessern. In diesem Teil des Codes versuche ich ein Geschäft mit einem Geldsystem Testen einer Variablen gegen 5 verschiedene mögliche Antworten zu programmierenIch habe Probleme mit meinen elif Aussagen
while True:
choice=str(input("What would you like to buy? (Type in 'nothing' when you don't want anymore items) "))
if choice!="health potion" and "strength potion" and "strength booster" and "armour piece" and "nothing":
print()
next_line=input("I do not understand what you wrote. Try again please ")
print()
elif choice=="nothing":
next_line=input("The merchant says 'Thanks for business' ")
print()
break
elif choice=="health potion":
gold=gold-10
if gold<0:
gold=gold+10
next_line=input("Sorry but you don't have enough gold ")
print()
else:
next_line=input("You bought a health potion ")
health_potions=health_potions+1
next_line=input("You now have "+str(gold)+" gold coins ")
print()
elif choice=="strength potion":
gold=gold-15
if gold<0:
gold=gold+15
next_line=input("Sorry but you don't have enough gold ")
print()
else:
next_line=input("You bought a strength potion ")
strength_potions=strength_potions+1
next_line=input("You now have "+str(gold)+" gold coins ")
print()
elif choice=="strength booster":
gold=gold-45
if gold<0:
gold=gold+45
next_line=input("Sorry but you don't have enough gold ")
print()
else:
next_line=input("You boosted your strength ")
strength_booster=strength_booster+1
next_line=input("You now have "+str(gold)+" gold coins ")
print()
elif choice=="armour piece":
gold=gold-30
if gold<0:
gold=gold+30
next_line=input("Sorry but you don't have enough gold ")
print()
else:
next_line=input("You bought an armour piece ")
armour=armour+1
next_line=input("You now have "+str(gold)+" gold coins ")
print()
Bei der Eingabe health potion
der Code auf wie normalen geht aber mit den anderen Eingängen geht es zu dieser Teil des Codes
if choice!="health potion" and "strength potion" and "strength booster" and "armour piece" and "nothing":
print()
next_line=input("I do not understand what you wrote. Try again please ")
print()
Mögliche Duplikat [Wie ich eine Variable gegen mehrere Werte testen?] (Https://stackoverflow.com/questions/15112125/how-do-i-test-one-variable-against-multiple- Werte) – jonrsharpe
Diese Frage ist mehrere Variablen für mehrere Werte nicht eine Variable wie in meinem Code @jonrsharpe – Ricardo
Ändern Sie Ihre dritte Zeile zu 'wenn Wahl in (" Gesundheitstrank "," Stärketrank "," Stärke Booster "," Rüstung Stück " "Nichts"): ' –