猜拳练习游戏(回炉练习)
__author__ = 'zht' #!/usr/bin/env python # -*- coding: utf-8 -*- ''' #努力学习每一天 ''' #1、导入随机数模块 import random #2、判断输入的是否为数字 while True: try: Player = int(input("\033[1;35m请输入:剪刀(0),石头(1),布(2)!\033[0m")) if isinstance(Player,int) == True: #3、定义随机数0-2 Computer = random.randint(0,2) #4、对输入的数字判断是否相等 if (Player == 1) and (Computer == 0) or (Player == 0) and (Computer == 2) or (Player == 2) and (Computer == 1): print("恭喜你你赢的了比赛") break elif Player == Computer: print("这把是平局,在来一把!") else: print("不好意思你输了,不要走,决战到天亮!") except Exception as Message: print("请按要求输入整数数字类型,不要做非法输入。请从新输入!")