4.json 2.6 KB
Newer Older
每日一练社区's avatar
test  
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
{
   "question_id": 7411744,
   "question_title": "编写Python程序实现素数处理的功能",
   "question_content": "<p style=\"margin-left:0cm; margin-right:0cm\">编写Python程序实现素数处理的功能&#xff0c;要求如下&#xff1a;</p><p style=\"margin-left:0cm; margin-right:0cm\">&#xff08;1&#xff09;从键盘输入一个整数X&#xff0c;编写一个函数Find&#xff08;x&#61;100&#xff09;&#xff0c;找出1—X之间的所有的素数&#xff08;即质数&#xff09;&#xff0c;并将这些素数按照升序存放在列表 prime_list []中。</p><p style=\"margin-left:0cm; margin-right:0cm\">&#xff08;2&#xff09;在程序中编写一个函数delete_seven( prime_list)&#xff0c;将 prime_list []中个位含有7的素数删除&#xff1b;</p><p style=\"margin-left:0cm; margin-right:0cm\"><strong>【程序要求&#xff1a;】</strong></p><p style=\"margin-left:0cm; margin-right:0cm\">&#xff08;1&#xff09;有引导用户键盘输入的提示信息&#xff0c;言语要恰当&#xff1b;</p><p style=\"margin-left:0cm; margin-right:0cm\">&#xff08;2&#xff09;函数Find&#xff08;x&#61;100&#xff09;实现要正确&#xff0c;实现列表 prime_list []中查询到的素数的输出&#xff1b;</p><p style=\"margin-left:0cm; margin-right:0cm\">&#xff08;3&#xff09;函数delete_seven( prime_list)实现正确&#xff0c;输出删除指定素数后的相关数据信息。</p>",
   "difficulty": "简单",
   "answer_id": 53363059,
   "answer_content": "<pre>\n<code>def find(x&#61;100):\n    pl &#61; []\n    for m in range(2,x&#43;1):\n        for k in pl:\n            if m % k &#61;&#61; 0:\n                break\n        else:\n            pl.append(m)\n    return pl\n\ndef delete_seven(pl):\n    return [x for x in pl if x%10!&#61;7]\n\nx &#61; int(input(&#39;输入一个整数:&#39;))\nprime_list &#61; find(x)\nprint(prime_list)\nprint(delete_seven(prime_list))\n\n</code></pre>\n\n<p><img alt=\"\" height=\"90\" src=\"https://img-ask.csdnimg.cn/upload/1617100202885.png\" width=\"421\" /></p>",
   "tag_name": "python",
   "python": "def find(x=100):\n\tpl = []\n\tfor m in range(2,x+1):\n\t\tfor k in pl:\n\t\t\tif m % k == 0:\n\t\t\t\tbreak\n\t\telse:\n\t\t\tpl.append(m)\n\treturn pl\ndef delete_seven(pl):\n\treturn [x for x in pl if x%10!=7]\nx = int(input('输入一个整数:'))\nprime_list = find(x)\nprint(prime_list)\nprint(delete_seven(prime_list))",
   "topic_link": "https://bbs.csdn.net/topics/600470199",
   "status": 1,
   "keywords": "散列表,算法中阶,数据结构,散列函数",
   "license": "csdn.net",
   "notebook": {
      "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/4.ipynb?type=file"
   },
   "notebook_enable": 1
}