'''
1. 出拳
玩家:手动输入
电脑:1.固定输入2.随机
2.判断输赢
2.1玩家获胜
2.2平局
2.3电脑获胜
'''
import random
# 玩家出拳
player = int(input('请出拳:0--石头 ;1--剪刀 ;2--布:'))
# 电脑出拳
# computer = 1(电脑固定出剪刀)
'''
电脑出拳变成随机:
1.导出random模块
import 模块名
2.使用random模块中的随机整数功能
random.randint(开始,结束)
'''
computer = random.randint(0,2)
# print(computer)
'''
玩家一定赢:
玩家:石头 电脑:剪刀
玩家:剪刀 电脑:布
玩家:布 电脑:石头
'''
# 玩家获胜
if ((player == 0)and(computer == 1)) or ((player == 1)and(computer == 2)) or ((player == 2)and(computer == 0)):
print('玩家获胜')
elif player == computer:
print('平局')
# 电脑获胜
else:
print('电脑获胜')
python学习笔记 “出拳游戏”
最新推荐文章于 2022-08-30 15:53:56 发布