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/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 0000000..86c1147 Binary files /dev/null and b/first30/Exercise 3/count oddeven/__pycache__/test_countoddeven.cpython-27-PYTEST.pyc differ diff --git a/first30/Exercise 3/count oddeven/__pycache__/test_pallindrome.cpython-27-PYTEST.pyc b/first30/Exercise 3/count oddeven/__pycache__/test_pallindrome.cpython-27-PYTEST.pyc new file mode 100644 index 0000000..116b1f3 Binary files /dev/null and b/first30/Exercise 3/count oddeven/__pycache__/test_pallindrome.cpython-27-PYTEST.pyc differ 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 0000000..5daee9b Binary files /dev/null and b/first30/Exercise 3/count oddeven/countoddeven.pyc differ diff --git a/first30/Exercise 3/count oddeven/firstdigit.py b/first30/Exercise 3/count oddeven/firstdigit.py new file mode 100644 index 0000000..08cc918 --- /dev/null +++ b/first30/Exercise 3/count oddeven/firstdigit.py @@ -0,0 +1,39 @@ +# First digit of the given integer: + + +def Firstdigit(N): + + flag=True + + count=0 + A=N + while(N>10): + 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 0000000..f141ad7 Binary files /dev/null and b/first30/Exercise 3/count oddeven/firstdigit.pyc differ 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 0000000..6105713 Binary files /dev/null and b/first30/Exercise 3/count oddeven/pallindrome.pyc differ 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 0000000..bc32059 Binary files /dev/null and b/first30/Exercise 3/countinteger/__pycache__/test_countinteger.cpython-27-PYTEST.pyc differ diff --git a/first30/Exercise 3/countinteger/countinteger.py b/first30/Exercise 3/countinteger/countinteger.py new file mode 100644 index 0000000..524751e --- /dev/null +++ b/first30/Exercise 3/countinteger/countinteger.py @@ -0,0 +1,15 @@ +#Count the Number of integers in a Given Number + +def countdigits(N): + + count=0 + + while(N>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 0000000..82a5e85 Binary files /dev/null and b/first30/Exercise 3/countinteger/countinteger.pyc differ diff --git a/first30/Exercise 3/digitcounting.py b/first30/Exercise 3/digitcounting.py new file mode 100644 index 0000000..7ba86c6 --- /dev/null +++ b/first30/Exercise 3/digitcounting.py @@ -0,0 +1,8 @@ +#Write a program to count the number of in an integer: + + +def Digitcounting(N): + + count=0 + + \ No newline at end of file diff --git a/first30/Exercise 3/digitdivision.py b/first30/Exercise 3/digitdivision.py new file mode 100644 index 0000000..a8bcbb9 --- /dev/null +++ b/first30/Exercise 3/digitdivision.py @@ -0,0 +1,21 @@ +# Check if all digits of a given N Divides N: + + +def Digitdivision(N): + + flag=True + + I=N + while (N>0): + 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 0000000..b7d891c Binary files /dev/null and b/first30/Exercise 3/digitdivision.pyc differ 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 0000000..18e4715 Binary files /dev/null and b/first30/Exercise 3/reverse.pyc differ 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 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 diff --git a/first30/Exercise 3/test_digitdivision.py b/first30/Exercise 3/test_digitdivision.py new file mode 100644 index 0000000..fb5adf7 --- /dev/null +++ b/first30/Exercise 3/test_digitdivision.py @@ -0,0 +1,17 @@ +#Test condition for the Digit division: +import digitdivision + + +def test_canassertTrue(): + assert True + +def test_digitdivision(): + actual= digitdivision.Digitdivision(123) + expected=False + assert actual==expected + +def test_digitdivision1(): + actual = digitdivision.Digitdivision(36) + expected=True + assert actual==expected + diff --git a/first30/Exercise 3/test_reverse.py b/first30/Exercise 3/test_reverse.py new file mode 100644 index 0000000..9eb134f --- /dev/null +++ b/first30/Exercise 3/test_reverse.py @@ -0,0 +1,9 @@ +#Test condition for reverse: +import reverse +def test_canassertTrue(): + assert True + +def test_reverseofdigits(): + actual=reverse.Reverseint(1234) + expected=4321 + assert actual==expected \ No newline at end of file diff --git a/first30/allprimes.py b/first30/allprimes.py new file mode 100644 index 0000000..9aa1f2e --- /dev/null +++ b/first30/allprimes.py @@ -0,0 +1,23 @@ +#print all prime numbers 2 to n: + +def Isprime(n): + flag=True + for i in range(2,n**1/2): + if n%i==0: + flag=False + break + return flag + +def printprimes(N): + if (N>=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 0000000..0f5f45e Binary files /dev/null and b/first30/newprime.pyc differ diff --git a/first30/nextprime.py b/first30/nextprime.py new file mode 100644 index 0000000..85bf28c --- /dev/null +++ b/first30/nextprime.py @@ -0,0 +1,13 @@ +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)) \ No newline at end of file diff --git a/first30/nextprime.pyc b/first30/nextprime.pyc new file mode 100644 index 0000000..5f2a37b Binary files /dev/null and b/first30/nextprime.pyc differ diff --git a/first30/nprimes.py b/first30/nprimes.py new file mode 100644 index 0000000..052e69d --- /dev/null +++ b/first30/nprimes.py @@ -0,0 +1,29 @@ +#print n prime numbers: + +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 + if (N>=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 0000000..02bfed5 Binary files /dev/null and b/first30/previousprime.pyc differ 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/first30/two/sumofprimes.py b/first30/two/sumofprimes.py new file mode 100644 index 0000000..6400a73 --- /dev/null +++ b/first30/two/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)) + + +