If elif else not working1
Question:
def scene3():
print("After you defeated the Giant Spider you encounter a Dark Dragon do you want to Attack or Run:? ")
encounter = input("Do you want to attack the Dragon?: [Attack/Run]")
if encounter.strip().lower() == "Attack":
print("You Attack the Dark Dragon and DIED apparently this rare monster is to much for you game over")
quit()
elif encounter.strip().lower() =="Run":
print("You successfully outrun the Dark Dragon and landed in a Capital City in Magical World")
time.sleep(delay2)
output:
After you defeated the Giant Spider you encounter a Dark Dragon do you want to Attack or Run:?
Do you want to attack the Dragon?: [Attack/Run]run
Process finished with exit code 0
Answers:
Your if
and else
condition should check for string with lowercase
when using lower.()
.
Please change the code to this:
import time
delay2 = 5
def scene3():
print("After you defeated the Giant Spider you encounter a Dark Dragon do you want to Attack or Run:? ")
encounter = input("Do you want to attack the Dragon?: [Attack/Run]")
if encounter.strip().lower() == "attack":
print("You Attack the Dark Dragon and DIED apparently this rare monster is to much for you game over")
quit()
elif encounter.strip().lower() == "run":
print("You successfully outrun the Dark Dragon and landed in a Capital City in Magical World")
time.sleep(delay2)
scene3()
O/P:
$ python3 test.py
After you defeated the Giant Spider you encounter a Dark Dragon do you want to Attack or Run:?
Do you want to attack the Dragon?: [Attack/Run]attack
You Attack the Dark Dragon and DIED apparently this rare monster is to much for you game over
$ python3 test.py
After you defeated the Giant Spider you encounter a Dark Dragon do you want to Attack or Run:?
Do you want to attack the Dragon?: [Attack/Run]run
You successfully outrun the Dark Dragon and landed in a Capital City in Magical World
def scene3():
print("After you defeated the Giant Spider you encounter a Dark Dragon do you want to Attack or Run:? ")
encounter = input("Do you want to attack the Dragon?: [Attack/Run]")
if encounter.strip().lower() == "Attack":
print("You Attack the Dark Dragon and DIED apparently this rare monster is to much for you game over")
quit()
elif encounter.strip().lower() =="Run":
print("You successfully outrun the Dark Dragon and landed in a Capital City in Magical World")
time.sleep(delay2)
output:
After you defeated the Giant Spider you encounter a Dark Dragon do you want to Attack or Run:?
Do you want to attack the Dragon?: [Attack/Run]run
Process finished with exit code 0
Your if
and else
condition should check for string with lowercase
when using lower.()
.
Please change the code to this:
import time
delay2 = 5
def scene3():
print("After you defeated the Giant Spider you encounter a Dark Dragon do you want to Attack or Run:? ")
encounter = input("Do you want to attack the Dragon?: [Attack/Run]")
if encounter.strip().lower() == "attack":
print("You Attack the Dark Dragon and DIED apparently this rare monster is to much for you game over")
quit()
elif encounter.strip().lower() == "run":
print("You successfully outrun the Dark Dragon and landed in a Capital City in Magical World")
time.sleep(delay2)
scene3()
O/P:
$ python3 test.py
After you defeated the Giant Spider you encounter a Dark Dragon do you want to Attack or Run:?
Do you want to attack the Dragon?: [Attack/Run]attack
You Attack the Dark Dragon and DIED apparently this rare monster is to much for you game over
$ python3 test.py
After you defeated the Giant Spider you encounter a Dark Dragon do you want to Attack or Run:?
Do you want to attack the Dragon?: [Attack/Run]run
You successfully outrun the Dark Dragon and landed in a Capital City in Magical World