欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python学习-6 猜拳小游戏

程序员文章站 2022-04-09 11:27:26
import random # 调用随机数模块 pc = random.randint(1,3) # 产生1-3的随机数 print("来玩个猜拳游戏吧!") a = '石头' b = '剪刀' c = '布' user = input('请输入(石头,剪刀,布):') if user == '石头... ......
import random                       # 调用随机数模块
pc = random.randint(1,3)            # 产生1-3的随机数

print("来玩个猜拳游戏吧!")

a = '石头'
b = '剪刀'
c = '布'

user = input('请输入(石头,剪刀,布):')

if user == '石头':
    print("你出了石头")
elif user == '剪刀':
    print("你出了剪刀")
else:
    print("你出了布")


if pc == 1:
    print('电脑出了石头')
elif pc == 2 :
    print('电脑出了剪刀')
else:
    print('电脑出了布')


if user == '石头' and pc == 2 or user =='剪刀' and pc == 3 or pc == 3 or user == '布' and pc == 1:
    print("你赢了")
elif user == '石头' and pc ==3 or user == '剪刀' and pc == 1 or user == '布' and pc == 2:
    print('你输了')
else:
    print('平局')