[Tutor] AD&D Character generator problems
Borgulya Gabor
borgulya@pons.sote.hu
Wed, 5 Apr 2000 13:35:17 +0200 (CEST)
On Tue, 4 Apr 2000 sjb@crosswinds.net wrote:
> # generate stats for the character
> statlist= ['str', 'dex', 'con', 'int', 'wis', 'cha']
> stats= {'str': 0, 'dex': 0, 'con': 0, 'int': 0, 'wis': 0, 'cha': 0}
>
> def MakeStats():
> for genstat in statlist:
> stats[genstat]= random.randint(3, 18)
> for stat in statlist:
> print stat, ':', stats[stat]
Hi!
A shorter version for the code fragment above:
#statlist= ['str', 'dex', 'con', 'int', 'wis', 'cha']
stats= {'str': 0, 'dex': 0, 'con': 0, 'int': 0, 'wis': 0, 'cha': 0}
def MakeStats():
for stat in stata.keys():
stats[stat]= random.randint(3, 18)
print stat, ':', stats[stat]
So the list statlist is not needed. Of course if you plan to add other
keys to the stats vocabulary, it may be a practical way to keep the
statlist to know which values have to be randomized.
Yours,
Gabor