基本上你能想到的地方都有了
import random
print("————————————————————")
print(">>>猜数字<<<")
t = 'Y'
while (t == 'Y'):
#初始化开始
print("请输入你想猜的数字的范围:从Mix到Max的非负整数")
Mix = -2.718281828459
Max = -3.141592653589
while not Mix < Max:
tempMix = input("Mix:")
while not tempMix.isdigit():
tempMix = input("你必须输入一个数字,而且是非负整数,Mix:")
Mix = int(tempMix)
tempMax = input("Max:")
while not tempMax.isdigit():
tempMax = input("你必须输入一个数字,而且是非负整数,Max:")
Max = int(tempMax)
if Mix >=Max:
print("再输一遍!Mix必须比Max小")
secret = random.randint(Mix,Max)
tempN = input("你想有多少次猜数字的机会?N=")
while not tempN.isdigit():
tempN = input("你必须输入一个数字,N:")
N = int(tempN)
guess = -5.201314
#初始化结束
while guess != secret and N > 0:
temp = input("你猜的数字是:")
N = N - 1
while not temp.isdigit():
temp = input("你必须输入一个非负整数")
guess = int(temp)
if guess == secret:
print("恭喜你猜对了")
else:
if guess > secret and N > 0:
print("太大了,你还有"+ str(N) + "次机会")
else:
if N >0:
print("太小了,你还有"+ str(N) + "次机会")
if N == 0:
print("很遗憾你输了")
t = input("你想再玩一遍么?\n输入\"Y\"继续,输入其他退出游戏:")
print("游戏结束")