猜拳游戏(基于python面向对象2)

来源:互联网 发布:詹姆斯身体素质知乎 编辑:程序博客网 时间:2024/06/05 07:46

第2阶段

编写计算机类(Computer) 需求    1 属性有名字name  , 积分 score    2 行为 出拳(showFist)    3 测试计算机出拳

代码如下:

import  random#创建用户类class Computer():    #构造函数    def __init__(self,name,score):        self.name=name        self.score= score    # 出拳    def showFist(self):        type = random.randint(1,3)        if type==1:            print(self.name,"出剪刀")        elif type==2:            print(self.name,"出石头")        elif type==3:            print(self.name,"出布")        return  type
原创粉丝点击