8
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 the HP reduce it to a value equal to or less than zero and in doing so indicate that the monster has been defeated, but I am having basically two problems:
- I want the player to have the option of attacking or not and present a message in case he decides not to attack.
- I want to present a victory message, which appears only when the player beats the monster.
Here’s 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 presented and the message indicating that the player does not want to attack is always appearing. Could someone help me?
Consider adding an explanation of why the OP application does not work, since it is using application to apply knowledge of python cycles and conditions. Other than that good answer +1
– lazyFox
@lazyFox, I was just adding that, edited reply. I am leaving the computer now, in case you see that you are missing/improving you are welcome to edit my answer. Thank you
– Miguel