Ok, so i've been trying to learn how to use def function. I tried to make a simple archery game based on chance.
If the shot misses, then this happens
I have no idea what I did wrong. Any help would be much appreciated.
Code:
import random
loop=1
HP=100
def shot(z):
if z<50:
return 50
print ("Direct Hit")
elif z >= 50:
print ("Missed")
while loop==1:
h=random.random()*100
n=shot(h)
choice=raw_input("Pick a shot type(shot, headshot)")
if choice == "shot":
HP=100-n
if HP<=0:
print ('You win')
loop=0
print (HP)
print (h)
Traceback (most recent call last):
File "/home/usr/Desktop/archery.py", line 15, in <module>
HP=100-n
TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'
File "/home/usr/Desktop/archery.py", line 15, in <module>
HP=100-n
TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'
Comment