From ba8be6e05af9e1509d90d732ca50357f2a6ec50b Mon Sep 17 00:00:00 2001 From: UdhaikuumarMohan Date: Thu, 10 Jan 2019 11:00:49 +0530 Subject: [PATCH 1/4] initial commit --- sumofprimes.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 sumofprimes.py diff --git a/sumofprimes.py b/sumofprimes.py new file mode 100644 index 0000000..6400a73 --- /dev/null +++ b/sumofprimes.py @@ -0,0 +1,32 @@ +# Find the sum of pime numbers less than N: + +import math +def Isprime(N): + flag=True + + if(N<=1): + flag=False + if(N==2): + return flag + + for i in range(2,int(math.sqrt(N)+1)): + if N%i==0: + flag=False + break + return flag + + + +def sumofprimes(N): + sum=2 + for X in range(3,N+1,2): + if(Isprime(X)): + sum=sum+X + + return sum + +N=input("Enter the value of N:") +print(sumofprimes(N)) + + + From 5aa7eb1d59a6166f54435ee1277bf1a59b17c426 Mon Sep 17 00:00:00 2001 From: UdhaikuumarMohan Date: Thu, 10 Jan 2019 11:53:46 +0530 Subject: [PATCH 2/4] Solutions for first 30 added --- first30/Exercise 3/count oddeven/Lastdigit.py | 15 ++++++ .../test_countoddeven.cpython-27-PYTEST.pyc | Bin 0 -> 2230 bytes .../test_pallindrome.cpython-27-PYTEST.pyc | Bin 0 -> 1599 bytes .../Exercise 3/count oddeven/countoddeven.py | 21 ++++++++ .../Exercise 3/count oddeven/countoddeven.pyc | Bin 0 -> 683 bytes .../Exercise 3/count oddeven/firstdigit.py | 39 +++++++++++++++ .../Exercise 3/count oddeven/firstdigit.pyc | Bin 0 -> 738 bytes .../count oddeven/lengthofpallindrome.py | 33 ++++++++++++ .../Exercise 3/count oddeven/pallindrome.py | 21 ++++++++ .../Exercise 3/count oddeven/pallindrome.pyc | Bin 0 -> 542 bytes .../count oddeven/test_countoddeven.py | 17 +++++++ .../count oddeven/test_pallindrome.py | 9 ++++ .../countinteger/.pytest_cache/README.md | 8 +++ .../.pytest_cache/v/cache/lastfailed | 1 + .../.pytest_cache/v/cache/nodeids | 4 ++ .../test_countinteger.cpython-27-PYTEST.pyc | Bin 0 -> 1489 bytes .../Exercise 3/countinteger/countinteger.py | 15 ++++++ .../Exercise 3/countinteger/countinteger.pyc | Bin 0 -> 371 bytes first30/Exercise 3/digitcounting.py | 8 +++ first30/Exercise 3/digitdivision.py | 21 ++++++++ first30/Exercise 3/digitdivision.pyc | Bin 0 -> 404 bytes first30/Exercise 3/ktheven.py | 24 +++++++++ first30/Exercise 3/reverse.py | 13 +++++ first30/Exercise 3/reverse.pyc | Bin 0 -> 428 bytes first30/Exercise 3/test_digitdivision.py | 17 +++++++ first30/Exercise 3/test_reverse.py | 9 ++++ first30/allprimes.py | 23 +++++++++ first30/countprimes.py | 26 ++++++++++ first30/factors.py | 20 ++++++++ first30/function.py | 0 first30/immediateprime.py | 47 ++++++++++++++++++ first30/kthprime.py | 25 ++++++++++ first30/mnprimes.py | 36 ++++++++++++++ first30/mul.py | 1 + first30/newprime.py | 21 ++++++++ first30/newprime.pyc | Bin 0 -> 472 bytes first30/nextprime.py | 13 +++++ first30/nextprime.pyc | Bin 0 -> 384 bytes first30/nprimes.py | 29 +++++++++++ first30/oddoreven.py | 6 +++ first30/onlykthprime.py | 26 ++++++++++ first30/previousprime.py | 14 ++++++ first30/previousprime.pyc | Bin 0 -> 431 bytes first30/prime.1.py | 16 ++++++ first30/prime.py | 11 ++++ first30/two/digitalroot.py | 17 +++++++ first30/two/perfecetsq.py | 16 ++++++ first30/two/perfectsquare.py | 14 ++++++ first30/two/sumofdigits.py | 14 ++++++ sumofprimes.py => first30/two/sumofprimes.py | 0 50 files changed, 650 insertions(+) create mode 100644 first30/Exercise 3/count oddeven/Lastdigit.py create mode 100644 first30/Exercise 3/count oddeven/__pycache__/test_countoddeven.cpython-27-PYTEST.pyc create mode 100644 first30/Exercise 3/count oddeven/__pycache__/test_pallindrome.cpython-27-PYTEST.pyc create mode 100644 first30/Exercise 3/count oddeven/countoddeven.py create mode 100644 first30/Exercise 3/count oddeven/countoddeven.pyc create mode 100644 first30/Exercise 3/count oddeven/firstdigit.py create mode 100644 first30/Exercise 3/count oddeven/firstdigit.pyc create mode 100644 first30/Exercise 3/count oddeven/lengthofpallindrome.py create mode 100644 first30/Exercise 3/count oddeven/pallindrome.py create mode 100644 first30/Exercise 3/count oddeven/pallindrome.pyc create mode 100644 first30/Exercise 3/count oddeven/test_countoddeven.py create mode 100644 first30/Exercise 3/count oddeven/test_pallindrome.py create mode 100644 first30/Exercise 3/countinteger/.pytest_cache/README.md create mode 100644 first30/Exercise 3/countinteger/.pytest_cache/v/cache/lastfailed create mode 100644 first30/Exercise 3/countinteger/.pytest_cache/v/cache/nodeids create mode 100644 first30/Exercise 3/countinteger/__pycache__/test_countinteger.cpython-27-PYTEST.pyc create mode 100644 first30/Exercise 3/countinteger/countinteger.py create mode 100644 first30/Exercise 3/countinteger/countinteger.pyc create mode 100644 first30/Exercise 3/digitcounting.py create mode 100644 first30/Exercise 3/digitdivision.py create mode 100644 first30/Exercise 3/digitdivision.pyc create mode 100644 first30/Exercise 3/ktheven.py create mode 100644 first30/Exercise 3/reverse.py create mode 100644 first30/Exercise 3/reverse.pyc create mode 100644 first30/Exercise 3/test_digitdivision.py create mode 100644 first30/Exercise 3/test_reverse.py create mode 100644 first30/allprimes.py create mode 100644 first30/countprimes.py create mode 100644 first30/factors.py create mode 100644 first30/function.py create mode 100644 first30/immediateprime.py create mode 100644 first30/kthprime.py create mode 100644 first30/mnprimes.py create mode 100644 first30/mul.py create mode 100644 first30/newprime.py create mode 100644 first30/newprime.pyc create mode 100644 first30/nextprime.py create mode 100644 first30/nextprime.pyc create mode 100644 first30/nprimes.py create mode 100644 first30/oddoreven.py create mode 100644 first30/onlykthprime.py create mode 100644 first30/previousprime.py create mode 100644 first30/previousprime.pyc create mode 100644 first30/prime.1.py create mode 100644 first30/prime.py create mode 100644 first30/two/digitalroot.py create mode 100644 first30/two/perfecetsq.py create mode 100644 first30/two/perfectsquare.py create mode 100644 first30/two/sumofdigits.py rename sumofprimes.py => first30/two/sumofprimes.py (100%) diff --git a/first30/Exercise 3/count oddeven/Lastdigit.py b/first30/Exercise 3/count oddeven/Lastdigit.py new file mode 100644 index 0000000..caf5dc7 --- /dev/null +++ b/first30/Exercise 3/count oddeven/Lastdigit.py @@ -0,0 +1,15 @@ +# Last digit of the given integer + +import firstdigit + +def Lastdigit(N): + + X=N%10 + return X + + if(Firstdigit(N)==Lastdigit(N)): + print("First and last digit are same") + +N=input("Enter the value of N: ") +Lastdigit(N) + diff --git a/first30/Exercise 3/count oddeven/__pycache__/test_countoddeven.cpython-27-PYTEST.pyc b/first30/Exercise 3/count oddeven/__pycache__/test_countoddeven.cpython-27-PYTEST.pyc new file mode 100644 index 0000000000000000000000000000000000000000..86c11477bca7d2efdcdc2be70fc1711306d3a703 GIT binary patch literal 2230 zcmeH|%}x|S5XWowV|IZ>1eM@zFDBzbA|G-vU?9lB#BAaq7cyot%=E&nvoo9SUWH`2 zh$pYUfN$W{=kOIgd-4JFUp+I3fF{O-lbh|D?yByt?yg^TSHDe;zx%Y{J+p{HDt;Aw z*HP3HhzNg+5~5wJtXHU4rCyD8>l9V!ElhT4YS3p zk!mQLD2g>2U!S5n#qd-mZBeg6Cqyr8Qujz3m*{h1kz6&+IuAiJt#W@jTbVt^G`2A| zXk?7Azd;wXk!{C@pAJUB)isDfDIs%*rE~s2sY{!8dXSrDF}#K z-0Xsh$)ZmeSkx%4Fe^D01tqZ=Qs-_=$)Rc5MUyE3ur{qkjbDd-D2L^6eJqEa!Ud$8 z3>Rj&#&nKQnP5eYH0A=RO&ZnM=ULjY481VKLai-87IJEZB5PKQ-IfATQdwU zfdKSoLvr^LD=Qc z{+U>pQ{^13F5kfJO%}JZc#pC=if zjCmJR!T3F zH{b<$1CHF0coNQ>cmVj%IBuiTD@68Y=VNzfcYfpQuld%?ZyWwsB8u?JuYz$Kui+ua z<4{U;;FR+U^{dpc(LtT!3VnpBQJR``(4@F3${Aj`=hm=E@*BUN1aKg->N#G+8jJsc z;yNV=P$lb7zd{#8ZyRJDla)yDxo}8tiCE_)5VI=#$2Ho#caCiuVrp^G(bvjJLEVMAXlEoa1oJC<@aUqfn#>Xsr>hI%-#t$Q<{TF#O8mP<~e?LA6 z6aTdeb(Unuo!wKVqr@n`oOIUwC?93ElgF`or!rqoG7Qr+$zq)k)bjAmE+T;FBV;5g z^W||?hOdI02JI9u)giG;YW))vl%S6)J6t}lS%uCW8skB^F|W|LLgvS$=W+RM)RRKyuxHQ}VjfNjQLWO~`>a#?}bmvY%9Uf{aPcmcC{ z=5vfmixr4JE8Z;{*Eq;DZ#YLxAfId6OTGgy!!6bA8os&-b)9Zk09*xt3>PY_BCBGL zU4^MIvZFAaK)LEc{TIFKSX@B6E?7+B6!V*dU56W6xQw)AqNXZs=OMo`QyRhF?qU6VKd zC+T-MZ|>!(Ti~M^Hjs1MX*g{F{)rZ7iCj4)-(paH8-hUY#6DmpItN=V7so^&FKhK) yC${(yTxu=f+QcGv?eUHt2lVb^xH`Vf{(ZM|0k;NuJWACw>2X%HX_01YZRZaVX>`#5 literal 0 HcmV?d00001 diff --git a/first30/Exercise 3/count oddeven/countoddeven.py b/first30/Exercise 3/count oddeven/countoddeven.py new file mode 100644 index 0000000..d7e310a --- /dev/null +++ b/first30/Exercise 3/count oddeven/countoddeven.py @@ -0,0 +1,21 @@ +#Count the even and odd digits in an integer: + +def countoddeven(N): + + oddcount=0 + evencount=0 + + while(N>0): + x=N%10 + N=N//10 + + if(x==1 or x%2!=0): + oddcount+=1 + elif(x!=0 and x%2==0): + evencount+=1 + + print ("Total odd numbers in the given integer", oddcount) + print ("Total even numbers in the given integer", evencount) + +#N=input("Enter the integer:") +#countoddeven(N) diff --git a/first30/Exercise 3/count oddeven/countoddeven.pyc b/first30/Exercise 3/count oddeven/countoddeven.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5daee9b5e1718b12ef23baf59c771e734a42fdba GIT binary patch literal 683 zcmcIg%}T>S5T4!Cs?k!s^dLRtq&W%VK@bt4ih|OES}d}cm|feYZKAuIQlY)|J$wpZ z!|oY_RZc{60ceBaEM`PtyJ5q`YyixjGd;rA4eZ6HX1CBOp`2DdTCNJ{w{9ugfq z_6-5k3+9o-YzlK98P&inJ?GF`1Qpv}0L%lB0gO1<+?R?vinoOBrRw z1+_4&y-2ERpOgO2f`PnWvD}`DzW$c z>Nc^scT}-}I<^pi*IAu6S;#`(W)0S6TYQ6cW18-U7Wtjfv;Q5FuIqS`%VMlf{D`RG E3uBR10): + N%10 + count+=1 + N=N//10 + + X=(A//(10**count)) + Y=(A%10) + + print("The First digit of the given integer", X) + print("The Last digit of the given integer",Y) + + if (X!=Y): + flag=False + + return flag + +N=input("Enter the value: ") +print(Firstdigit(N)) + + + + + + + + + + + + diff --git a/first30/Exercise 3/count oddeven/firstdigit.pyc b/first30/Exercise 3/count oddeven/firstdigit.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f141ad7a8a261e236334c25ba9cac615bdd4717e GIT binary patch literal 738 zcmbtRO;5r=5S`s30it5m5JO_J#~zRa9yG)ljX^z_9?AhjdTH228=zo!K}_JJ|JXm^ z%vABNB=dMPo!K`Z-set5R$9>jzJC(`uh47*K?8gM^pOZA0*nML;ax!A1B0$dTxbuv zegO*x0)dE!c7tYn2w1%qumV_1ST=}YWK@8x&0IoFtOVdAXL%Yb)YkwnRp{mMbBePv z`Umy32df{&AVC30Dg-3%lgqt0as#)8IGD~;$Nn|rW1dB+_JqE-qtv`cou$bJi8bmp z;tDm@+AK^O4U^0|ojfJ3IeT-Yb-Rhsw00i>WKk4FRg^?U>`F4;1}${6jTSoj_%#|y zK-X~qmxztw7bGJIS(CPWcc1bJx<1thJfl5E%Hk?cwHn9PDQ--~nNc>L7@q_~>dKW7 z9x#Iw@;F8yr04##fsl53h-OO&fU_3lk+3!7oz$63xo4vm@px|3bf|*13iu%06xZ@m jl5{qAAwBTh3$s6*g!;IcO!a(hF8Lru43ziErET#A^__^9 literal 0 HcmV?d00001 diff --git a/first30/Exercise 3/count oddeven/lengthofpallindrome.py b/first30/Exercise 3/count oddeven/lengthofpallindrome.py new file mode 100644 index 0000000..f1acf8b --- /dev/null +++ b/first30/Exercise 3/count oddeven/lengthofpallindrome.py @@ -0,0 +1,33 @@ +# Find out the length of the pallindrome: + + +def Lengthofpallindrome(N): + + flag=True + + count=0 + X=N + Reverse=0 + while(N>0): + temp=(N%10) + count+=1 + Reverse=Reverse*10+temp + N=N//10 + + if not(Reverse==X): + return False + + + print flag + + + if not(count%2==0): + return ("The given pallindrome is in odd length") + + return("The given pallindrome is in even length") + + + +#Input +N=input("Enter the Integer: ") +print(Lengthofpallindrome(N)) \ No newline at end of file diff --git a/first30/Exercise 3/count oddeven/pallindrome.py b/first30/Exercise 3/count oddeven/pallindrome.py new file mode 100644 index 0000000..046654b --- /dev/null +++ b/first30/Exercise 3/count oddeven/pallindrome.py @@ -0,0 +1,21 @@ +# Find the given number is pallindrome or not: + +def Ispallindrome(N): + + flag=True + + X=N + Reverse=0 + while(N>0): + temp=(N%10) + Reverse=Reverse*10+temp + N=N//10 + + if not(Reverse==X): + flag=False + + return flag + +#Input +#N=input("Enter the Integer: ") +#print(Ispallindrome(N)) \ No newline at end of file diff --git a/first30/Exercise 3/count oddeven/pallindrome.pyc b/first30/Exercise 3/count oddeven/pallindrome.pyc new file mode 100644 index 0000000000000000000000000000000000000000..610571377c968d86b2db790768dd057fd74da85f GIT binary patch literal 542 zcmcIg!Ab)$5Piw6Rg0~cs-TxW?#YAVMMQ*ZL69D*r6M`F?8druH(QgeRM@@w6Mm;Z z;3O#e0|w^h&CE;YCBbK}d+>20QhYB)`vryR5oEwS@IZv&Hs(}GU4M+6Gu1xs>=KgdTa$vD=1d0%RP6Cd3}eoQ7k+1zvVAqh7<3M@2|iAH@QLc&dMsQ3wiGS GQI0RuRCh`M literal 0 HcmV?d00001 diff --git a/first30/Exercise 3/count oddeven/test_countoddeven.py b/first30/Exercise 3/count oddeven/test_countoddeven.py new file mode 100644 index 0000000..3e04657 --- /dev/null +++ b/first30/Exercise 3/count oddeven/test_countoddeven.py @@ -0,0 +1,17 @@ +#Test condition for count odd even: + +def test_assertTrue(): + assert True + +import countoddeven + +def test_countoddeven(): + actual=countoddeven.countoddeven(1234) + expected=2 + assert expected==actual + + +def test_countoddeven(): + actual=countoddeven.countoddeven(1234) + expected=2 + assert expected==actual \ No newline at end of file diff --git a/first30/Exercise 3/count oddeven/test_pallindrome.py b/first30/Exercise 3/count oddeven/test_pallindrome.py new file mode 100644 index 0000000..b3d71b3 --- /dev/null +++ b/first30/Exercise 3/count oddeven/test_pallindrome.py @@ -0,0 +1,9 @@ +def test_canassertTrue(): + assert True + + +import pallindrome +def test_pallindrome(): + actual=pallindrome.Ispallindrome(1221) + expected=True + assert expected==actual \ No newline at end of file diff --git a/first30/Exercise 3/countinteger/.pytest_cache/README.md b/first30/Exercise 3/countinteger/.pytest_cache/README.md new file mode 100644 index 0000000..bb78ba0 --- /dev/null +++ b/first30/Exercise 3/countinteger/.pytest_cache/README.md @@ -0,0 +1,8 @@ +# pytest cache directory # + +This directory contains data from the pytest's cache plugin, +which provides the `--lf` and `--ff` options, as well as the `cache` fixture. + +**Do not** commit this to version control. + +See [the docs](https://docs.pytest.org/en/latest/cache.html) for more information. diff --git a/first30/Exercise 3/countinteger/.pytest_cache/v/cache/lastfailed b/first30/Exercise 3/countinteger/.pytest_cache/v/cache/lastfailed new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/first30/Exercise 3/countinteger/.pytest_cache/v/cache/lastfailed @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/first30/Exercise 3/countinteger/.pytest_cache/v/cache/nodeids b/first30/Exercise 3/countinteger/.pytest_cache/v/cache/nodeids new file mode 100644 index 0000000..f197d95 --- /dev/null +++ b/first30/Exercise 3/countinteger/.pytest_cache/v/cache/nodeids @@ -0,0 +1,4 @@ +[ + "test_countinteger.py::test_canassertTrue", + "test_countinteger.py::test_countintegerofgivennumber" +] \ No newline at end of file diff --git a/first30/Exercise 3/countinteger/__pycache__/test_countinteger.cpython-27-PYTEST.pyc b/first30/Exercise 3/countinteger/__pycache__/test_countinteger.cpython-27-PYTEST.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bc320594d9f7959f6cb5637b72f70a3ff676bb13 GIT binary patch literal 1489 zcmb_b%}x_h6h70RX@MewiQ>kvF&P&U{v^>*10ig?7+jGilc954r%Y#>d+!J&Wh1_U zFW?)vaO3;9cI5-;cg}RMA}eFV9M11Of8VM8Se*a*WuyC@h#DPSHmOmPy9NPz=6oBLwtrc7XJf^>J%eE zm8?U<3SASOxn!P`l}zxtc1Z7uSmzLkX_ft>8tp#3!ZWTI8#ECk?C;?s^&fjK@^lb| zRQEtaW0baQPrdQw#xrBNoHsgG$VCLz9X?(YCZB7!Es*{3WpJ9uiH%c(#6(Hf3ln4K z3!7EO2BEgA5Ciiz%abV3YOI4nlAVT0kcJ~==foKH6(rtJfE=x2Hq z+CW{5lQ0b}jGk1n03%mX*f%|hB*bikJABnm)p_^mLg`*?)Y^8pm*pv{wQ8VrSL&P9 ztdB443gQX_5=kXIlRC79J0!=Yg90P0W0kCsk%P$&u{?*jf>i(rR}SxC;?NoR3Qa0x zzL6E+L@gHk@L!zz^s(<6#T5ntmNBfC>yIVGovu`0h*)lz*AD=?v>P@44Et1uNkRH^ z873l!0isPt4cL1Oy9t;DR@BHg#e0q>HST5>M(86V0D1`>cjA{DfVE7A&!ycqJijTT z*4k|W*A~FVg9>{#4-=mq@jel@sd`pLQ^0Nc(EWwX9RwGE+>w==B2U5Jo$NMn@r1`f z5zNl++p<;^Q9OvP@wpMZ3=#mxiGa12jmDu?KG)#$iTK=#-(VuwzyOxp>13($_ywPD z!(U{5iO&K_n>TWS*X>*Ki~oS%C!CfKZ?@5_KZxI{G|fk+N^`;HJ_tEWj_b4l;*YdU ztK>;5TyjvJbr4A7_Ax7Q9e8-X=mjUZuGP7YZE?dlTFaxET4bO;=kobk{}IUV9)0): + N%10 + count+=1 + N=N//10 + + return count + +#N=input("Enter the Number:") +#print(countdigits(N)) diff --git a/first30/Exercise 3/countinteger/countinteger.pyc b/first30/Exercise 3/countinteger/countinteger.pyc new file mode 100644 index 0000000000000000000000000000000000000000..82a5e85e760366da44415d6a071884d9b17d3b78 GIT binary patch literal 371 zcmbVH!D_-l6rA1IV$-JHJb3cBhY}AKN=qq%c+Ei(q2!hSb3*`mDSM(TLUAh-#gTLV-Cvkz T|4HnU>lP*K7Ua0): + x=N%10 + N=N//10 + if not (I%x==0): + flag=False + break + + return flag + +#Enter the Input: + +#N=input("Enter the Input:") +#print(Digitdivision(N)) \ No newline at end of file diff --git a/first30/Exercise 3/digitdivision.pyc b/first30/Exercise 3/digitdivision.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b7d891cc8d62facceaff83d5702fdcd42b3927b0 GIT binary patch literal 404 zcmb7o0*+`B>EX7-_zr~z-B3a&lzq&l)xA8M4>RvG%JPldkjg&40lI(pi^i` zjbX@b=>SP_K;N zp}3k=&SX;JI4_6pb2XcX^g6J~*g=3hq#B>*3-g&@Hl{ADGY2PmY3J6L_QN{6TpYcv vz5MpYc2OMM9swQeSfwiA-c_;c>q#cg_c8Hj^e?wQN6%iD<*G8HV8k51Yzs#1 literal 0 HcmV?d00001 diff --git a/first30/Exercise 3/ktheven.py b/first30/Exercise 3/ktheven.py new file mode 100644 index 0000000..441563e --- /dev/null +++ b/first30/Exercise 3/ktheven.py @@ -0,0 +1,24 @@ +# To Find the Kth Even Number + +#def Iseven(N): + + #if(N%2==0): + #return N + +def Ktheven(N): + count=0 + #X=N + #if(X%2==0): + #count+=1 + while(count!=K): + N+=1 + if(N%2==0): + count+=1 + return N + +N=input("Enter the Number: ") +K=input("Enter the Number: ") + +print(Ktheven(N)) + + \ No newline at end of file diff --git a/first30/Exercise 3/reverse.py b/first30/Exercise 3/reverse.py new file mode 100644 index 0000000..aa5d08b --- /dev/null +++ b/first30/Exercise 3/reverse.py @@ -0,0 +1,13 @@ +#Reverse a Given Number + +def Reverseint(N): + Reverse=0 + while(N>0): + temp=(N%10) + Reverse=Reverse*10+temp + N=N//10 + return Reverse + +#Input +#N=input("Enter the Integer:") +#print(Reverseint(N)) \ No newline at end of file diff --git a/first30/Exercise 3/reverse.pyc b/first30/Exercise 3/reverse.pyc new file mode 100644 index 0000000000000000000000000000000000000000..18e4715736d6ea9f4fc79c4b43567d1215d800c2 GIT binary patch literal 428 zcmb_W%}N6?7@VZVpT+7$6g>5~ClA_F5fy50vWJ!;NG?k@)L?g8lT<3~-h3?I$`^35 zt@r{ae3SVy!}m?+yO+$r21;Xh1mAm>?-2^%6L=;On5L3HI_e!(Y(^}9N1)sYY_3qZ z{Iv@=Y`Mf)BT)+!5~sDqIc?D+anS&8hj^kkP2<4K5?~WT8d>`p;<_yC6DQ`~IB!Ci zJeYE|HL-yo6GlTd^E9Yj8>b$YdR>|-cr`0ta;qLq?kZc&`{Rvq+IpjYN&i~8?c~eV wM~K^Zi)=2): + print(2) + + for i in range(3,N+1,2): + if(Isprime(i)): + print(i) + +N=input("Enter the number N:") +print ("primes") +printprimes(N) + + \ No newline at end of file diff --git a/first30/countprimes.py b/first30/countprimes.py new file mode 100644 index 0000000..ee39657 --- /dev/null +++ b/first30/countprimes.py @@ -0,0 +1,26 @@ +#print count of prime numbers 2 to n: +import math +def Isprime(n): + flag=True + for i in range(2,int(math.sqrt(n)+1)): + if n%i==0: + flag=False + break + return flag + +def countprimes(N): + count=0 + if (N>=2): + count+=1 + + + + for i in range(3,N+1,2): + if(Isprime(i)): + count+=1 + print("There are {0} prime numbers from 2 to{1}".format(count,N)) + +N=input("enter the number N:") +countprimes(N) + + \ No newline at end of file diff --git a/first30/factors.py b/first30/factors.py new file mode 100644 index 0000000..c5dd1b7 --- /dev/null +++ b/first30/factors.py @@ -0,0 +1,20 @@ + + +def factors(n): + count=0 + for i in range(1,n+1): + if (n%i==0): + count=count+1 + return count + print count + + +def IsPrime(n): + a=factors(n) + if(a==2): + print "prime" + else: + print "not prime" + +n=input("Enter the number n:") +IsPrime(n) \ No newline at end of file diff --git a/first30/function.py b/first30/function.py new file mode 100644 index 0000000..e69de29 diff --git a/first30/immediateprime.py b/first30/immediateprime.py new file mode 100644 index 0000000..f8edde4 --- /dev/null +++ b/first30/immediateprime.py @@ -0,0 +1,47 @@ +import newprime + +def nextprime(N): + + count=0 + i=N+1 + while(count<1): + if(newprime.Isprime(i)): + return i + i+=1 + +#N=input("Enter the value:") +#print(nextprime(N)) + + +def previousprime(N): + if(N<2): + return "no primes" + count=0 + i=N-1 + while(count<1): + if(newprime.Isprime(i)): + return i + i-=1 + +#N=input("Enter the value:") +#print(nextprime(N)) + + + + +def immediateprime(n): + + x1=nextprime(n) + y1=x1-n + + x2=previousprime(n) + y2=n-x2 + + if(y1<=y2): + return x1 + + else: + return x2 + +n=input("Enter the value of ") +print(immediateprime(n)) \ No newline at end of file diff --git a/first30/kthprime.py b/first30/kthprime.py new file mode 100644 index 0000000..da58343 --- /dev/null +++ b/first30/kthprime.py @@ -0,0 +1,25 @@ +#print kth prime from n: + +def Isprime(n): + flag=True + for i in range(2,n**1/2): + if n%i==0: + flag=False + break + return flag + +def nprimes(N): + count=0 + + while(count!=k): + N+=1 + if(Isprime(N)): + count+=1 + return N + + + + +N=input("enter the number N:") +k=input("enter the value k:") +print(nprimes(N)) \ No newline at end of file diff --git a/first30/mnprimes.py b/first30/mnprimes.py new file mode 100644 index 0000000..7c97d95 --- /dev/null +++ b/first30/mnprimes.py @@ -0,0 +1,36 @@ +#print all prime numbers 2 to n: +import math + + +def Isprime(n): + flag=True + for i in range(2,int(math.sqrt(n)+1)): + if n%i==0: + flag=False + break + return flag + +def printprimes(M,N): + count=0 + if(M==1 or M==2): + print(2) + count+=1 + if(M%2==0): + M+=1 + + for i in range(M,N+1,2): + if(Isprime(i)): + #print(i) + count+=1 + print(count) + + + +M=input("enter the number M:") +N=input("enter the number N:") + +if(M>N): + M,N=N,M +printprimes(M,N) + + \ No newline at end of file diff --git a/first30/mul.py b/first30/mul.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/first30/mul.py @@ -0,0 +1 @@ + diff --git a/first30/newprime.py b/first30/newprime.py new file mode 100644 index 0000000..be6b7df --- /dev/null +++ b/first30/newprime.py @@ -0,0 +1,21 @@ +import math + +def Isprime(N): + flag=True + if (N<=1): + flag=False + if (N==2): + return flag + + for i in range(2,int(math.sqrt(N)+1)): + + if (N%i==0): + flag=False + break + return flag + + +#N=input("Enter the value of N:") +#print(Isprime(N)) + + diff --git a/first30/newprime.pyc b/first30/newprime.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0f5f45efcdaa4f6f400a7dfc47d762c11a8fef09 GIT binary patch literal 472 zcmah^O-sW-6rA0pHI)h;q#`1Cj0pY!5fLl}FF~pxNIZlj*4Q*{vs*tPJ=MSGuki=y zytUxbW#8L*vv23kdS6?c!RJAoV!bra3x?Ta%D5Fu;GRI^gFp#$6MDQYzPX}Q5lY!& zTr$iHlLeLvje9>Dw(g&FPF2S}mdVJKMMw@VnI2Jk8dv#iJgss$XLT{jPiF6SgI8C^l`_NZFhR9d oS9KV^I?~&$0u_qep?Dm2nEu57oe;47Y%=2): + #print(2) + count+=1 + + + + i=3 + while(count!=N): + if(Isprime(i)): + count+=1 + i=i+2 + print i + + + +N=input("enter the number N:") +nprimes(N) \ No newline at end of file diff --git a/first30/oddoreven.py b/first30/oddoreven.py new file mode 100644 index 0000000..7f5041b --- /dev/null +++ b/first30/oddoreven.py @@ -0,0 +1,6 @@ +flag=False +n=10 +if n%2==0: + flag=True +else: + print flag \ No newline at end of file diff --git a/first30/onlykthprime.py b/first30/onlykthprime.py new file mode 100644 index 0000000..56aef9f --- /dev/null +++ b/first30/onlykthprime.py @@ -0,0 +1,26 @@ +#print kth prime from n: + +def Isprime(n): + flag=True + for i in range(2,n**1/2): + if n%i==0: + flag=False + break + return flag + +def nprimes(N): + count=0 + + while(count!=k): + N+=1 + if(Isprime(N)): + count+=1 + print(N) + + + + + +N=input("enter the number N:") +k=input("enter the value k:") +nprimes(N) \ No newline at end of file diff --git a/first30/previousprime.py b/first30/previousprime.py new file mode 100644 index 0000000..de2e032 --- /dev/null +++ b/first30/previousprime.py @@ -0,0 +1,14 @@ +import newprime + +def previousprime(N): + if(N<2): + return "no primes" + count=0 + i=N-1 + while(count<1): + if(newprime.Isprime(i)): + return i + i-=1 + +#N=input("Enter the value:") +#print(previous(N)) diff --git a/first30/previousprime.pyc b/first30/previousprime.pyc new file mode 100644 index 0000000000000000000000000000000000000000..02bfed569e3b6d2c65a40e77749f063d9b98f5ad GIT binary patch literal 431 zcma)1!Ait15S>Zux-Kj3Q4vJ&(u8;Hny4%zy)fIM6`eS~RAE0kW z!K+DT@+NQQ%_RBU9(@cB%8GuM!F>q}dvG-l)12rYz|cDY%S(|ZVBHs1UNNAAQh5yv zw{R=1d?e~7Qd!gqtyy1F+Fcu39@7d^DM`u=MWP4LhTfRED**)z^eJ+mj_3}P6xjxZ zb0>Ym7F^>G+s-X)a0tlB9GQ@D2-nybCF3T7X;7?FN6E{hXjQ&%qQ)*mNb17AFlQwM zO5fPB?d-Gj{g1*)`x>>iT}G9ZkB5mA^O#c}@Q8P?Q`SjlLd>MqpZ@=v3{i8w@O3}8 L7cy{=kB!YYfVxiX literal 0 HcmV?d00001 diff --git a/first30/prime.1.py b/first30/prime.1.py new file mode 100644 index 0000000..24fd2f6 --- /dev/null +++ b/first30/prime.1.py @@ -0,0 +1,16 @@ +def Isprime(n): + flag=True + for i in range(2,n**1/2): + if n%i==0: + flag=False + break + return flag + + +x=input("enter:") +if(Isprime(x)): + print x + + + + \ No newline at end of file diff --git a/first30/prime.py b/first30/prime.py new file mode 100644 index 0000000..96b88fe --- /dev/null +++ b/first30/prime.py @@ -0,0 +1,11 @@ +def Isprime(n): + flag=True + for i in range(2,n**1/2): + if n%i==0: + flag=False + break + print flag +n=input("enter the number n:") +print(Isprime(n)) +print n + \ No newline at end of file diff --git a/first30/two/digitalroot.py b/first30/two/digitalroot.py new file mode 100644 index 0000000..de20a23 --- /dev/null +++ b/first30/two/digitalroot.py @@ -0,0 +1,17 @@ +#Digital root + + +def digitalroot(N): + root=0 + while(N>0 or root>9): + if(N==0): + N=root + root=0 + + root+=N%10 + N=N/10 + + return root + +N=input("Enter the value of N:") +print(digitalroot(N)) \ No newline at end of file diff --git a/first30/two/perfecetsq.py b/first30/two/perfecetsq.py new file mode 100644 index 0000000..f0a19fc --- /dev/null +++ b/first30/two/perfecetsq.py @@ -0,0 +1,16 @@ +# Finding perfect squares by addding n odd numbers. + +def perfectsq(N): + flag=False + sum=0 + for i in range(1,N,2): + sum=sum+i + if (sum==N): + return True + + + return flag + + +N=input("Enter the value of N:") +print(perfectsq(N)) diff --git a/first30/two/perfectsquare.py b/first30/two/perfectsquare.py new file mode 100644 index 0000000..15c8562 --- /dev/null +++ b/first30/two/perfectsquare.py @@ -0,0 +1,14 @@ +#Finding the perfect square. + +import math +def perfectsquare(N): + flag=True + M = math.sqrt(N) + X = round(M) + if(M-X)==0: + return flag + else: + return False + +N=input("Enter the value of N:") + print(perfectsquare(N)) diff --git a/first30/two/sumofdigits.py b/first30/two/sumofdigits.py new file mode 100644 index 0000000..64532a4 --- /dev/null +++ b/first30/two/sumofdigits.py @@ -0,0 +1,14 @@ +#sum of digits + + +def sumofdigits(N): + sum=0 + while(N!=0): + x=N%10 + sum=sum+(x) + N=N/10 + + return sum + +N=input("Enter the value of N:") +print(sumofdigits(N)) \ No newline at end of file diff --git a/sumofprimes.py b/first30/two/sumofprimes.py similarity index 100% rename from sumofprimes.py rename to first30/two/sumofprimes.py From 14e6ec697c2c7f25ee1b7b63053107ce79e816b5 Mon Sep 17 00:00:00 2001 From: UdhaikuumarMohan Date: Thu, 10 Jan 2019 12:54:00 +0530 Subject: [PATCH 3/4] sum of squares added --- .vscode/settings.json | 3 +++ first30/Exercise 3/sumofsquares.py | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 first30/Exercise 3/sumofsquares.py diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3b4a779 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "C:\\anaconda\\python.exe" +} \ No newline at end of file diff --git a/first30/Exercise 3/sumofsquares.py b/first30/Exercise 3/sumofsquares.py new file mode 100644 index 0000000..a040ad2 --- /dev/null +++ b/first30/Exercise 3/sumofsquares.py @@ -0,0 +1,25 @@ +# Finding the perfect square and sum of perfect squares between N: +import math + +def Isperfectsq(N): + flag=True + M=math.sqrt(N) + X=round(M) + + if not (X-M==0): + flag=False + + return flag + +def Sumofperfectsq(N): + sum=0 + + for a in range(1,N+1): + + if(Isperfectsq(a)): + sum=sum+a + + return sum + +N=input("Enter the Value: ") +print(Sumofperfectsq(N)) \ No newline at end of file From f433ec1029860a79c9a9053ed21d6e8fecae113d Mon Sep 17 00:00:00 2001 From: UdhaikuumarMohan Date: Thu, 10 Jan 2019 14:28:12 +0530 Subject: [PATCH 4/4] sum of odd and even --- first30/Exercise 3/sumofeven.py | 12 ++++++++++++ first30/Exercise 3/sumofodd.py | 13 +++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 first30/Exercise 3/sumofeven.py create mode 100644 first30/Exercise 3/sumofodd.py diff --git a/first30/Exercise 3/sumofeven.py b/first30/Exercise 3/sumofeven.py new file mode 100644 index 0000000..2b1f79c --- /dev/null +++ b/first30/Exercise 3/sumofeven.py @@ -0,0 +1,12 @@ +#Find out the sum of even numbers between given N: + +def sumofeven(N): + sum=0 + + for a in range(2,N+1,2): + if (a%2==0): + sum+=a + return sum + +N=input("Enter the input: ") +print(sumofeven(N)) \ No newline at end of file diff --git a/first30/Exercise 3/sumofodd.py b/first30/Exercise 3/sumofodd.py new file mode 100644 index 0000000..fe7cb5e --- /dev/null +++ b/first30/Exercise 3/sumofodd.py @@ -0,0 +1,13 @@ +# sum of odd numbers between given N: + +def sumofodd(N): + sum=0 + + for a in range(1,N+1,2): + if not (a%2==0): + sum+=a + + return sum + +N=input("Enter the Number: ") +print(sumofodd(N)) \ No newline at end of file