solution.json 1.7 KB
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "53be93ad31624900a621d8a1980e3d15",
  "keywords": "猜大小",
  "title": "python 编程 猜数字",
  "desc": [
    {
      "content": "\n<p>游戏&#xff08;猜数字&#xff09;&#xff1a;随机生成一个数字&#xff08;取值范围&#xff3b;1&#xff0c;100&#xff3d;&#xff09;。让用户猜数字&#xff0c;并给出相应的提示&#xff1a;\n如果用户输入比答案大&#xff0c;提示‘Too big&#xff0c; try again’&#xff1b;\n反之&#xff0c;提示‘Too small, try again’&#xff1b;\n如果猜中了&#xff0c;提示‘Congratulations!’。\n最后&#xff0c;要给出反馈&#xff08;答案&#xff0c;猜的次数&#xff0c;猜的历史&#xff09;。\n</p>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "python"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ]
  ],
  "template": {
    "content": "import random\nv=random.randint(1,100)\ncount=0\nhis=[]\nwhile 1:\n\tvi=input(\"输入猜测值:\")\n\tcount+=1\n\this.append(vi)\n\tif int(vi)>v:\n\t\tprint(\"Too big,try again\")\n\tif int(vi)<v:\n\t\tprint(\"Too small,try again\")\n\tif int(vi)==v:\n\t\tprint('Congratulations!')\n\t\tbreak\nprint(\"答案是:%d\" % v)\nprint(\"猜测次数:%d\" % count)\nst=''\nfor i in his:\n\tst+=i\n\tst+=','\nst=st[:-1]\nprint(\"猜测历史:%s\" % st)",
    "language": "python"
  },
  "node_id": "dailycode-6a1541c03bbf441a9f896331a5d4cba1",
  "license": "csdn.net",
  "created_at": 1637894161,
  "topic_link": "https://bbs.csdn.net/topics/600469885"
}