Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

New to python and was my first try creating a loop, and after endless hours of trying to figure out what was wrong, I'm stumped. Here's the code:

if fightOptions == ' MELEE': dummyHealth - damage print ('Good job!') if damage > dummyHealth: time.sleep(2) print ('You defeated the training dummy!') gold = gold + 1 xp = xp + 2 if xp > 1: print ('You levelled up!') heroHealth + 5 damage = random.randint(4,22) while dummyHealth > damage: print ('You need to attack again!') fightOptions = input ('MELEE, ITEM or SKILL?') if fightOptions == ' MELEE': dummyHealth - damage if dummyHealth == 0: break time.sleep(2) print ('You defeated the training dummy!') gold = gold + 1 xp = xp + 2

the damage and dummyHealth are my own variables, damage being "damage = random.randint(2,20)" and dummyHealth being "dummyHealth = 100", whenever I run the code, it repeats the "print ('Good job!')" command and then the "print ('You need to attack again!')" "input ('MELEE, ITEM or SKILL?')" and then when anything is typed into the box, it just repeats the input command. Could you tell me what I've done wrong?

Thanks!

share|improve this question

closed as off-topic by Jamal Jan 12 at 19:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions containing broken code or asking for advice about code not yet written are off-topic, as the code is not ready for review. After the question has been edited to contain working code, we will consider reopening it." – Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.

    
Since this basic question may not do well on SO, I can probably tell you that the error is in the statement dummyHealth - damage. You need a slightly different operator for that. – Jamal Jan 12 at 19:20
    
Thanks, what do you recommend I change it to? – KekMeister Jan 12 at 19:22
1  
Since you're trying to deduct from dummyHealth, you need -=. Read up on the different operators here. – Jamal Jan 12 at 19:27

Browse other questions tagged or ask your own question.