fork download
  1. import random
  2.  
  3. # Game variables
  4. player_health = 100
  5. enemy_health = 50
  6. score = 0
  7.  
  8. # Simulate user input
  9. actions = ["1", "1", "2", "1", "3"] # Example actions
  10.  
  11. # Game loop
  12. for action in actions:
  13. # Display game state
  14. print("Score: {}, Player Health: {}, Enemy Health: {}".format(score, player_health, enemy_health))
  15.  
  16. if action == "1":
  17. # Attack enemy
  18. enemy_damage = random.randint(10, 20)
  19. enemy_health -= enemy_damage
  20. print("You attacked the enemy for {} damage!".format(enemy_damage))
  21.  
  22. # Enemy counterattack
  23. if enemy_health > 0:
  24. player_damage = random.randint(5, 15)
  25. player_health -= player_damage
  26. print("Enemy counterattacked for {} damage!".format(player_damage))
  27.  
  28. elif action == "2":
  29. # Heal player
  30. heal_amount = random.randint(10, 20)
  31. player_health += heal_amount
  32. print("You healed for {} health!".format(heal_amount))
  33.  
  34. elif action == "3":
  35. # Run away
  36. print("You ran away!")
  37. break
  38.  
  39. # Check game over
  40. if player_health <= 0:
  41. print("Game Over! Enemy wins.")
  42. break
  43. elif enemy_health <= 0:
  44. print("Game Over! You win.")
  45. score += 100
  46. break
Success #stdin #stdout 0.01s 9740KB
stdin
Standard input is empty
stdout
Score: 0, Player Health: 100, Enemy Health: 50
You attacked the enemy for 13 damage!
Enemy counterattacked for 12 damage!
Score: 0, Player Health: 88, Enemy Health: 37
You attacked the enemy for 20 damage!
Enemy counterattacked for 5 damage!
Score: 0, Player Health: 83, Enemy Health: 17
You healed for 16 health!
Score: 0, Player Health: 99, Enemy Health: 17
You attacked the enemy for 12 damage!
Enemy counterattacked for 9 damage!
Score: 0, Player Health: 90, Enemy Health: 5
You ran away!