Pyhton猜数小游戏

print("""
这是一个猜数游戏,
请猜一个0--10之间的数。
      """)
game_type = input("""
请输入游戏次数,
无限次游戏请输入forever,
n次游戏请输入n。
n:""")
if game_type == "forever" :
    print("无限次游戏模式")
else :
    game_type = int(game_type)
    print("游戏体验次数为:",game_type)
    
while game_type == "forever" or game_type :
    if isinstance(game_type, int) :
        game_type = game_type - 1
        if 0 == game_type :
            print("这是最后一次游戏机会了!!!")        
    temp = input("请输入一个数,或者输入q退出游戏:")
    if temp == 'q' :
        break
    num = int(temp)
    if num == secret_num :
        print("恭喜猜对")
        break
    else :
        print("猜错了")
        if num > secret_num :
           if 0 == game_type :
                print("最后一次游戏机会用完!!!")
           else :
                print("猜的过大,往小的猜")
        else :
            if 0 == game_type :
                print("最后一次游戏机会用完!!!")
                break
            else :
                print("猜的过小,往大的猜")

    
print("游戏结束")
    
    
发布了142 篇原创文章 · 获赞 11 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_38293453/article/details/104363242