我如何增加号码列表中的最小值和最大值?
how do i increase the min and max on my number list?
我正在 python 中创建游戏,但我 运行 在创建关卡系统时遇到了麻烦。你看她的攻击我创建了一个从 1(最小)到 10(最大)的列表,对于她获得的每个级别,我希望列表的最小值和最大值增加 1,但如果可能的话我应该怎么做?我在 python 3.2
中编码
char ={
'atk':[1,10],
'Hp':100,
'name': 'Ruby',
'Age': 1,
'weapon': 'Scythe',
'lvl': 1,
'xp': 0,
'nextlvl': 50,
'stats': {
'str': 1,
'dex': 1,
'vit': 1
}}
while char['xp'] >= char['nextlvl']:
char['lvl'] += 1
char['nextlvl'] = char['nextlvl'] * 3
char['stats']['str'] +=1
char['stats']['dex'] +=1
char['stats']['vit'] +=1
char['atk'] +=1 <-- my problems right here
print('level:', char['lvl'],'Exp:', char['xp'],'nextlvl:', char['nextlvl'])
print('STR:', char['stats']['str'], 'DEX:', char['stats']['dex'], 'VIT:', char['stats']['vit'])
以下将执行此操作:
char['atk'] = [atk + 1 for atk in char['atk']]
您也可以分别增加两个数字(最小值和最大值):
char['atk'][0] = char['atk'][0] + 1
char['atk'][1] = char['atk'][1] + 1
如果您认为这很笨拙,您可能需要考虑将最小值和最大值存储在两个单独的字典条目中。
我正在 python 中创建游戏,但我 运行 在创建关卡系统时遇到了麻烦。你看她的攻击我创建了一个从 1(最小)到 10(最大)的列表,对于她获得的每个级别,我希望列表的最小值和最大值增加 1,但如果可能的话我应该怎么做?我在 python 3.2
中编码char ={
'atk':[1,10],
'Hp':100,
'name': 'Ruby',
'Age': 1,
'weapon': 'Scythe',
'lvl': 1,
'xp': 0,
'nextlvl': 50,
'stats': {
'str': 1,
'dex': 1,
'vit': 1
}}
while char['xp'] >= char['nextlvl']:
char['lvl'] += 1
char['nextlvl'] = char['nextlvl'] * 3
char['stats']['str'] +=1
char['stats']['dex'] +=1
char['stats']['vit'] +=1
char['atk'] +=1 <-- my problems right here
print('level:', char['lvl'],'Exp:', char['xp'],'nextlvl:', char['nextlvl'])
print('STR:', char['stats']['str'], 'DEX:', char['stats']['dex'], 'VIT:', char['stats']['vit'])
以下将执行此操作:
char['atk'] = [atk + 1 for atk in char['atk']]
您也可以分别增加两个数字(最小值和最大值):
char['atk'][0] = char['atk'][0] + 1
char['atk'][1] = char['atk'][1] + 1
如果您认为这很笨拙,您可能需要考虑将最小值和最大值存储在两个单独的字典条目中。