2. 玩家与电脑玩石头剪刀布游戏,电脑玩家都随机出拳。1---代表石头,2---代表剪刀,3---代表布。程序提示玩家出拳,并判断电脑赢还是玩家赢。

def caiquan():    
print('请选择你要出的拳头:' '1.石头    2.剪刀   3.布')    
player = int(input())    
computer = random.randint(1, 3)    
print('玩家出的是%d 电脑出的是%d' % (player, computer))    
# 判断谁胜利    
if (player == 1 and computer == 2) or (player == 2 and computer == 3) or (            player == 3 and computer == 1):        
print('玩家胜利')    
elif player == computer:        
print('打平')    
else:       
print('电脑胜利')

caiquan()
发布了17 篇原创文章 · 获赞 5 · 访问量 339

猜你喜欢

转载自blog.csdn.net/weixin_45116412/article/details/104919932