print("0石头,1剪刀,2布,3退出") class game():#定义游戏类 def __init__(self,n): self.chu=int(n) import random self.a = random.randint(0, 2)#定义属性 def abcd(self):#定义方法 if self.a==0 and self.chu==1: print(self.chu,"您出剪刀") print(self.a,"机器人出石头") print("输了,真菜") if self.a==1 and self.chu==1: print(self.chu,"您出剪刀") print(self.chu,"机器人出剪刀") print("平局") if self.a==2 and self.chu==1: print(self.chu,"您出剪刀") print(self.a,"机器人出布") print("您赢了,你可真棒,真是个大聪明呢") if self.a==0 and self.chu==0: print(self.chu,"您出石头") print(self.a,"机器人出石头") print("平局") if self.a==1 and self.chu==0: print(self.chu,"您出石头") print(self.chu,"机器人出剪刀") print("您赢了,你可真棒,真是个大聪明呢") if self.a==2 and self.chu==0: print(self.chu,"您出石头") print(self.a,"机器人出布") print("输了,真菜") if self.a==0 and self.chu==2: print(self.chu,"您出布") print(self.a,"机器人出石头") print("您赢了,你可真棒,真是个大聪明呢") if self.a==1 and self.chu==2: print(self.chu,"您出布") print(self.chu,"机器人出剪刀") print("输了,真菜") if self.a==2 and self.chu==2: print(self.chu,"您出布") print(self.a,"机器人出布") print("平局") while True: bcd=int(input("")) cs=game(bcd)#调用 cs.abcd() if bcd==3: break
python石头剪刀布
猜你喜欢
转载自blog.csdn.net/m0_61344379/article/details/122121975
今日推荐
周排行