Skip to content

Commit 30d27e1

Browse files
authored
prime factorisation code for sourabh
1 parent 9ce5a0c commit 30d27e1

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

Prime Factorisation.ipynb

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"#To find the prime factors of any integer input"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 55,
15+
"metadata": {},
16+
"outputs": [
17+
{
18+
"name": "stdout",
19+
"output_type": "stream",
20+
"text": [
21+
"Please enter an integer number632\n"
22+
]
23+
},
24+
{
25+
"data": {
26+
"text/plain": [
27+
"[2, 4, 8, 79, 158, 316]"
28+
]
29+
},
30+
"execution_count": 55,
31+
"metadata": {},
32+
"output_type": "execute_result"
33+
}
34+
],
35+
"source": [
36+
"num= int(input(\"Please enter an integer number\"))\n",
37+
"mylist=[]\n",
38+
"for i in range(2, num):\n",
39+
" if (num%i==0):\n",
40+
" mylist.append(i)\n",
41+
"#mylist is list of all factors\n",
42+
"mylist "
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"execution_count": 56,
48+
"metadata": {},
49+
"outputs": [],
50+
"source": [
51+
"primefactors=[]"
52+
]
53+
},
54+
{
55+
"cell_type": "code",
56+
"execution_count": 57,
57+
"metadata": {},
58+
"outputs": [],
59+
"source": [
60+
"for j in mylist:\n",
61+
" #last=int(j/2)\n",
62+
" for l in range (2, j-1):\n",
63+
" if j%l==0:\n",
64+
" break\n",
65+
" else:\n",
66+
" primefactors.append(j)\n",
67+
" "
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": 58,
73+
"metadata": {},
74+
"outputs": [
75+
{
76+
"data": {
77+
"text/plain": [
78+
"[2, 79]"
79+
]
80+
},
81+
"execution_count": 58,
82+
"metadata": {},
83+
"output_type": "execute_result"
84+
}
85+
],
86+
"source": [
87+
"primefactors"
88+
]
89+
},
90+
{
91+
"cell_type": "code",
92+
"execution_count": null,
93+
"metadata": {},
94+
"outputs": [],
95+
"source": []
96+
}
97+
],
98+
"metadata": {
99+
"kernelspec": {
100+
"display_name": "Python 3",
101+
"language": "python",
102+
"name": "python3"
103+
},
104+
"language_info": {
105+
"codemirror_mode": {
106+
"name": "ipython",
107+
"version": 3
108+
},
109+
"file_extension": ".py",
110+
"mimetype": "text/x-python",
111+
"name": "python",
112+
"nbconvert_exporter": "python",
113+
"pygments_lexer": "ipython3",
114+
"version": "3.8.5"
115+
}
116+
},
117+
"nbformat": 4,
118+
"nbformat_minor": 4
119+
}

0 commit comments

Comments
 (0)