I'm a beginner in programming and I'm trying to make a simple little game to apply my knowledge about conditionals, repetition and the Random module, but I'm having some semantic problems.
My goal is to attack the monster with a random number between 1 and 6 until HP drops it to a value equal to or less than zero and when doing so indicates that the monster has expired, but I'm basically having two problems:
- I want the player to have the option to attack or not and to display a message in case he decides not to attack.
- I want to display a win message that appears only when the player wins the monster.
Here is the code:
from random import randint
print('Um monstro apareceu !')
hp=10
a=randint(1,6)
while hp-a>0:
hp=hp-a
d=input('Deseja atacar o monstro (S/N) ? ')
if d=='S':
print(hp-a,)
if hp<=0:
print('Você venceu o monstro !')
if d=='N':
print('Você fugiu !')
The problem is that the victory message is not being displayed and the message that the player does not want to attack is always appearing. Could someone help me?