python实现猜拳小游戏

Tyne ·
更新时间:2024-09-21
· 581 次阅读

用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(表示退出游戏) \n") if player.lower() == "q" : Flag = False print("游戏终止!") else: player = int(player) Rounds += 1 if robot == player: print("打平!") else: print("%s 赢得本局" % ("robot" if robot-player == 1 else "player")) def main(): mora_game() if __name__ == '__main__': main()

执行运行结果

您可能感兴趣的文章:如何用Python破解wifi密码过程详解Python基础教程之if判断,while循环,循环嵌套Python利用字典破解WIFI密码的方法正确理解Python中if __name__ == ''__main__''对python中数据集划分函数StratifiedShuffleSplit的使用详解浅谈python下tiff图像的读取和保存方法python使用if语句实现一个猜拳游戏详解



猜拳 小游戏 Python

需要 登录 后方可回复, 如果你还没有账号请 注册新账号