We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 653e1be commit 7f54af4Copy full SHA for 7f54af4
basic-input-output-in-python/adventure_game.py
@@ -4,7 +4,13 @@
4
enemy_health = 3
5
6
while health > 0 and enemy_health > 0:
7
- if input("Attack or Run? ").lower() == "attack":
+ # Normalize input to handle extra spaces and case variations.
8
+ action = input("Attack or Run? ").strip().lower()
9
+ if action not in {"attack", "run"}:
10
+ print("Invalid choice. Please type 'Attack' or 'Run'.")
11
+ continue
12
+
13
+ if action == "attack":
14
enemy_health -= 1
15
print("You hit the enemy!")
16
# Implement a 50% chance that the enemy strikes back.
basic-input-output-in-python/guess_the_number.py
@@ -6,4 +6,4 @@
if guess == number:
print("You got it!")
else:
- print(f"Sorry, the number was {number}.")
+ print("Sorry, the number was", number)
0 commit comments