鱼C论坛

 找回密码
 立即注册

猜数字游戏的终极版

已有 566 次阅读2014-7-29 11:26

基本上你能想到的地方都有了
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("游戏结束")


路过

鸡蛋

鲜花

握手

雷人

全部作者的其他最新日志

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-19 12:36

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

返回顶部