Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I don't know what is wrong!
#2
You are trying to modify a global within a function.  Consider this illegal (it is possible but highly discouraged so I'm not showing it).

Make attack take hp as an argument and return the new hp instead.
So your function could look like this:
def attack(hit_points):
    diceValue = random.randint(1, 10)
    return hit_points - diceValue
And could be invoked like this:
hp = attack(hp)
Reply


Messages In This Thread
RE: I don't know what is wrong! - by Mekire - Dec-16-2016, 08:31 PM
RE: I don't know what is wrong! - by wavic - Dec-16-2016, 08:37 PM
RE: I don't know what is wrong! - by Mekire - Dec-16-2016, 08:40 PM
RE: I don't know what is wrong! - by wavic - Dec-16-2016, 08:43 PM
RE: I don't know what is wrong! - by sparkz_alot - Dec-16-2016, 08:47 PM
RE: I don't know what is wrong! - by Mekire - Dec-16-2016, 08:51 PM
RE: I don't know what is wrong! - by wavic - Dec-16-2016, 08:57 PM
RE: I don't know what is wrong! - by Mekire - Dec-16-2016, 09:05 PM
RE: I don't know what is wrong! - by nilamo - Dec-16-2016, 09:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 5,370 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  python gives wrong string length and wrong character thienson30 2 4,136 Oct-15-2019, 08:54 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020