您的位置:首页 > 编程语言 > Python开发

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

2017-08-19 13:04 309 查看
第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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: