python newbie

Philip Swartzleonard starx at pacbell.net
Sun Apr 7 16:30:26 EDT 2002


Aahz || Sun 07 Apr 2002 01:02:01p:

> In article <d9ea2696.0204071156.4284b1f1 at posting.google.com>,
> distrex <distrex at hotmail.com> wrote:
>>
>>I'm trying my first script with a module and I can't get it to work
>>right.  I'm using the time module to make part of the game random and
>>i just want the number to be at a whole number (no decimals) and I
>>can't figure out how to make it do that. If someone needs me to post
>>the script I'd be happy to but if you can help me just from memory
>>that'd be great too. Thanx in advance.
> 
> Use the random module.

Yep. For example:

---
import random

# No vaule - uses time on it's own
random.seed()

orcs_to_place = random.randrange(12,30)

def percent_chance( percentage ):
    	"Assumes percentage as number 0-100"
    	if random.random() > (percentage / 100.0):
    	    	return 1
    	else:
    	    	return 0

def die_roll( number, sides ):
    	total = 0
    	for not_used in number:
    	    	total += random.rand_range(1, sides)
    	return total
---

This is all just off the top of my head, but i've made functions like 
this before.

-- 
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com



More information about the Python-list mailing list