#猜拳小游戏 : |
#1.控制台输入 ,使用input函数,限制输入整数 |
#2.对手是电脑,随机出拳,用到random函数 |
#import random导入 随机模块 |
#3.决定胜负 |
#你瀛的情况: |
#你 电脑 |
#石头 剪刀 |
#布 石头 |
#剪刀 布 |
# 平局的情况 |
#你和电脑出的一样 |
import random |
ni = int ( input ( '请出拳;剪刀(0),石头(1),布(2):' )) |
com = random.randint( 0 , 2 ) #0 到二随机输出数字 |
print (f '电脑出拳的是{com}' ) |
#你胜的情况; |
if ((ni = = 0 ) and (com = = 2 )) or ((ni = = 1 ) and (com = = 0 )) or ((ni = = 2 ) and (com = = 1 )): |
print ( '恭喜你,手气不错,赢了' ) |
#平局的情况 |
elif ni = = com: |
print ( '平局,要不要再来一把' ) |
#你数输了的情况 |
else : |
print ( '你输了,洗洗手在来吧' ) |
#拓展 |
#随机数 |
#random.choice('剪刀','石头','布') #电脑出拳 |