#!/usr/bin/env python import os import random import sys import time def yanse(s): print(‘\033[25;31;40m %s \033[0m‘ %s) def menu(): #print(‘ @@@@@@@@开始猜数字游戏@@@@@@@@‘) #print(‘ @@@@@@@@只有3次机会@@@@@@@@‘) a= ‘开始猜数字游戏‘ b=‘只有3次机会‘ #print(a.center(40,‘#‘)) yanse(a.center(40,‘#‘)) yanse(b.center(42,‘#‘)) #print(b.center(42,‘#‘)) #print(a.rjust(40)) #print(a.ljust(40)) def kaishi(): Num = random.randint(1, 10) j = 0 count = 0 menu() while count <= 3: count += 1 num = input(‘请输入1-10的数字>>> :‘) if num.isdigit(): num=int(num) if num > Num: print(‘猜大了‘) elif num <Num: print(‘猜小了‘) else: print(‘恭喜猜对了‘) time.sleep(1) print(‘是否继续玩:Y/N‘) s = input(‘>>>Y|y :‘) if s in [‘Y‘, ‘y‘]: # print(‘是否重新生成随机数:Y/y‘) # s1 = input(‘>>>Y|y‘) # if s1 in [‘Y‘, ‘y‘]: Num = random.randint(1, 10) print(‘已重新生成随机数,祝您游戏愉快‘) count = 0 else: print(‘再见,常来玩呀‘) sys.exit(2) if count == 3: print(‘机会用完是否继续‘,‘继续玩:Y/y,其他退出‘) s = input(‘>>>Y|y :‘) if s in [‘Y‘,‘y‘]: print(‘是否重新生成随机数:Y/y‘) s1 = input(‘>>>Y|y :‘) if s1 in [‘Y‘, ‘y‘]: Num = random.randint(1,10) print(‘已重新生成随机数,祝您游戏愉快‘) else: print(‘请继续猜,加油*_*‘) j += 1 #print(j) if j > 1: print(‘都错6次了还有脸玩...一边玩去‘) sys.exit(3) count = 0 else: print(‘真是笨...0-0‘) sys.exit(4) else: print(‘输入非数字,重新输入‘) count-=1 continue kaishi()
原文:https://www.cnblogs.com/mxdboke/p/9222193.html