{"question_id":7411744,"question_title":"编写Python程序实现素数处理的功能","question_content":"<p style=\"margin-left:0cm; margin-right:0cm\">编写Python程序实现素数处理的功能,要求如下:</p><p style=\"margin-left:0cm; margin-right:0cm\">(1)从键盘输入一个整数X,编写一个函数Find(x=100),找出1—X之间的所有的素数(即质数),并将这些素数按照升序存放在列表 prime_list []中。</p><p style=\"margin-left:0cm; margin-right:0cm\">(2)在程序中编写一个函数delete_seven( prime_list),将 prime_list []中个位含有7的素数删除;</p><p style=\"margin-left:0cm; margin-right:0cm\"><strong>【程序要求:】</strong></p><p style=\"margin-left:0cm; margin-right:0cm\">(1)有引导用户键盘输入的提示信息,言语要恰当;</p><p style=\"margin-left:0cm; margin-right:0cm\">(2)函数Find(x=100)实现要正确,实现列表 prime_list []中查询到的素数的输出;</p><p style=\"margin-left:0cm; margin-right:0cm\">(3)函数delete_seven( prime_list)实现正确,输出删除指定素数后的相关数据信息。</p>","difficulty":"简单","answer_id":53363059,"answer_content":"<pre>\n<code>def find(x=100):\n pl = []\n for m in range(2,x+1):\n for k in pl:\n if m % k == 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!=7]\n\nx = int(input('输入一个整数:'))\nprime_list = 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}