python_if判断_四_随机数

 

 

 1 #!/usr/bin/env python
 2 # -*- coding: utf-8 -*-
 3 import random
 4 #需求
 5 #从控制台输出要出的拳--石头(1)/剪刀(2)/布(3)
 6 #电脑随机出拳--先
 7 #比较胜负
 8 player = int(input("请输入你要出的拳(石头(1)/剪刀(2)/布(3)):"))
 9 computer = random.randint(1,3)
10 
11 print("玩家选择的是 %d - 电脑出的是 %d " % (player,computer))
12 if ((player == 1 and computer ==2)
13         or (player == 2 and computer == 3)
14         or (player == 3 and computer == 1)):
15 
16     print("电脑输了")
17 elif player == computer:
18     print("平局")
19 else:
20     print("电脑赢了")

 

posted @ 2018-06-21 15:38  翱翔的菜鸟  阅读(311)  评论(0编辑  收藏  举报