python 初识类

import random
class Dice:
    def __init__(self):
        self.face=None
    def roll(self):
        self.face = (random.randint(1, 6), random.randint(1, 6))
    def total(self):
        return sum(self.face)
d1=Dice()
d1.roll()
print(d1.face)
print(d1.total())

你可能感兴趣的:(python)