Professional Documents
Culture Documents
Game Potions
Game Potions
class Player:
def __init__(self, name, health):
self.name = name
self.health = health
def use_random_potion(self):
potion = random.choice(["Healing Potion", "Poison Potion"])
if potion == "Healing Potion":
health_recovered = random.randint(10, 20)
self.health += health_recovered
print(f"{self.name} used a Healing Potion and recovered
{health_recovered} health.")
elif potion == "Poison Potion":
damage_taken = random.randint(5, 15)
self.health -= damage_taken
print(f"{self.name} used a Poison Potion and took {damage_taken}
damage.")
def main():
player_name = input("Enter your character's name: ")
player = Player(player_name, 100)
while True:
print(f"\n{player.name}'s Health: {player.health}")
if choice == "1":
player.use_random_potion()
if player.health <= 0:
print("Game over! You've lost all your health.")
break
elif choice == "2":
print("Exiting the game.")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()