attack_vals = {标签:name,val,type,age,大战,面向对象,attack,人狗,data From: https://www.cnblogs.com/jingshiwhy/p/17255203.html
'田园犬':30,
'迪':80,
}
def dog(name,d_type):
data = {
'name': name,
'd_type': d_type,
# 'attack_val':30,
'life_val': 100
}
if d_type in attack_vals:
data['attack_val'] = attack_vals[d_type]
else:
data['attack_val'] = 15
return data
def person(name,age):
data={
'name':name,
'age':age,
'life_val': 100
}
if age >18:
data['attack_val'] =50
else:
data['attack_val'] = 30
return data
sh1 = dog('wjl', '田园犬')
sh2 = dog('wjl2', '迪')
hs1 = person('wjl1', 19)
print(sh1,sh2)
print(hs1)