赞
踩
9-13 使用OrderedDict
from collections import OrderedDict
favorite_languages = OrderedDict()
favorite_languages['ken'] = 'c'
favorite_languages['jack'] = 'PHP'
favorite_languages['ben'] = 'JAVA'
favorite_languages['phile'] = 'R'
for name, language in favorite_languages.items():
print(name.title() + "'s favorite language is:" + language.title())
9-14 骰子
from random import randint class Die(): def __init__(self,sides=6): self.sides = sides def roll_die(self): self.sides = randint(1,6) print(self.sides) def roll_die_10(self): self.sides = randint(1,10) print(self.sides) def roll_die_20(self): self.sides = randint(1,20) print(self.sides) die = Die(6) print("6") for i in range(0,10): die.roll_die() print("10") for i in range(0,10): die.roll_die_10() print("20") for i in range(0,10): die.roll_die_20()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。