提交 e89b8ea9 编写于 作者: Miykael_xxm's avatar Miykael_xxm 🚴

上传新文件

上级 ad665e2e
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "271eb153",
"metadata": {},
"outputs": [],
"source": [
"import math,re\n",
"def prime(num):\n",
"\tflag = False\n",
"\tif num > 1:\n",
"\t\tfor i in range(2, math.floor(math.sqrt(num))):\n",
"\t\t\tif (num % i) == 0:\n",
"\t\t\t\tflag = True\n",
"\t\t\t\tbreak\n",
"\tif flag:\n",
"\t\tprint(num, \"不是素数\")\n",
"\telse:\n",
"\t\tprint(num, \"是素数\")\n",
"\treturn flag\n",
"s = input(\"请输入字符串:\")\n",
"sList = re.findall(r'(\\d+)', s)\n",
"sNum = [int(x) for x in sList]\n",
"y = lambda x: 0 if prime(x) else x\n",
"sNew = [y(x) for x in sNum]\n",
"print(sNum) \n",
"print(sNew) "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5ea0b5d1",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册