Dec-16-2016, 08:24 PM
I was trying to code a dice game but i cant seem to get the goomba to take damage. I would appreciate some help.
import random monNum = 1 y = 0 hp = 10 def attack(): diceValue = random.randint(1, 10) hp = hp - diceValue while(y==0): if(monNum==1): print("A goomba has crossed your path!") print() command = input("What will you do?:") print() if(command == "help"): print("attack") print() elif(command == "attack"): attack() elif(command == "dice"): print(diceValue) print() else: print() else: print()
Output:#This is whatever i get when i try run the code
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:16:59) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
==== RESTART: C:\Users\\OneDrive\Documents\New folder (2)\test.py ====
A goomba has crossed your path!
What will you do?:attack
Traceback (most recent call last):
File "C:\Users\William\OneDrive\Documents\New folder (2)\test.py", line 22, in <module>
attack()
File "C:\Users\William\OneDrive\Documents\New folder (2)\test.py", line 8, in attack
hp = hp - diceValue
UnboundLocalError: local variable 'hp' referenced before assignment
>>>