Python Forum

Full Version: Newbie to Python, Need help with how to impliment random values
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone, I just started doing Python after I learned a little bit of the language in Computer Science class. (A program at my school.) I am making an RPG and just wondering how I implement random values. For example, the player does between 3-5 damage to enemy, and when the system chooses a value, it subtracts from the monster's HP. Thanks alot for helping.  Smile
(Dec-19-2016, 12:49 AM)Yoriz Wrote: [ -> ]Use the random module

Okay, but what about number ranges? (3-5, 1-2, etc.)
Yes
(Dec-19-2016, 12:53 AM)Yoriz Wrote: [ -> ]Yes

Oh wait I saw. Now how do I make that random value subtract from a variable?
variable - random_value
(Dec-19-2016, 01:08 AM)Yoriz Wrote: [ -> ]
variable - random_value

Wow! Thanks again!  Smile
Now if you don't mind me asking one more... how do you use greater than or less than to compare variables and values? (if variable > 0)
Suggest you take a basic python tutorial
Yes that is correct
if variable > 0:
    print('Greater than 0')
if variable < 10:
    print('Less than 10')
if 10 > variable > 0:
    print('Its between')