zoukankan      html  css  js  c++  java
  • Python作业之:猜数游戏

    import random  #随机函数
    secret = random.randint(1,10) #secret 取1到10随机数
    print("猜数游戏" .center(50,"-"))
    times = 3
    guess = 0
    # print("不妨猜一下我现在心里想的是哪一个数字:",end="")
    # print("不妨猜一下我现在心里想的是哪一个数字:")
    while (guess != secret)and(times > 0):
    team = input("不妨猜一下我现在心里想的是哪一个数字:")
    guess = int(team)
    times -=1
    if guess == secret:
    print("你是我肚子里的蛔虫吗?\n猜对了也没有奖励的哈哈!")
    else:
    if guess > secret:
    print("大了,大了兄弟.")
    else:
    print("小了,小了笨蛋.")
    if times > 0:
    # print("再试一次吧笨蛋",end="")
    print("再试一次吧笨蛋!")
    else:
    print("机会用光了噢噢_@_")
    print("game over,goodbye!")





    升级版:
    import random  #随机函数
    secret = random.randint(1,10) #secret 取1到10随机数
    print("猜数游戏" .center(50,"-"))
    times = 3
    guess = 0
    print("不妨猜一下我现在心里想的是哪一个数字?",end='')
    while (guess != secret) and (times > 0):
    team = input("请输入一个数字:")
    while not team.isdigit():
    print("抱歉,输入不合法,", end='')
    team = input("请重新输入一个数字:")
    guess = int(team)
    times -= 1
    if guess == secret:
    print("你是我肚子里的蛔虫吗?\n猜对了也没有奖励的哈哈!")
    else:
    if guess > secret:
    print("大了,大了兄弟.")
    else:
    print("小了,小了笨蛋.")
    if times > 0:
    # print("再试一次吧笨蛋",end="")
    print("再试一次吧笨蛋!")
    else:
    print("机会用光了噢噢_@_")
    print("game over,goodbye!")

    代码摘至:鱼C论坛课后作业
  • 相关阅读:
    Nginx配置文件nginx.conf中文详解(转)
    windows Nginx基本使用方法
    phpstorm 找到文件修改历史
    微信小程序模拟点击出现问题解决方法
    设置头像、商品、轮播图为背景图时需要的css
    div左右居中css
    自定义方形复选框
    css 调转180度:transform: rotate(180deg);
    js字符串转数字(小数),数字转字符串
    腾讯地图key秘钥
  • 原文地址:https://www.cnblogs.com/ouwen/p/7201395.html
Copyright © 2011-2022 走看看