用python实现猜拳小游戏,供大家参考,具体内容如下
本练习旨在养成良好的编码习惯和练习逻辑思考.
1、使用python版本: 3.7.3;
2、代码内容实现如下
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
简单实现猜拳小游戏,默认每回合 五局
Version: 0.1
Author: smartbabble
Date: 2018-03-12
"""
from random import randint
def mora_game():
Rounds = 0
Flag = True
while Flag and Rounds < 5:
robot = randint(1,3)
player = input("游戏开始请出招:"
"1(表示剪刀),"
"2(表示石头),"
"3(表示布),"
"q或Q(表示退出游戏) ")
if player.lower() == "q" :
Flag = False
print("游戏终止!")
else:
player = int(player)
Rounds += 1
if robot == player:
print("打平!")