Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "C:\\anaconda\\python.exe"
}
15 changes: 15 additions & 0 deletions first30/Exercise 3/count oddeven/Lastdigit.py
Original file line number Diff line number Diff line change
@@ -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)

Binary file not shown.
Binary file not shown.
21 changes: 21 additions & 0 deletions first30/Exercise 3/count oddeven/countoddeven.py
Original file line number Diff line number Diff line change
@@ -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)
Binary file added first30/Exercise 3/count oddeven/countoddeven.pyc
Binary file not shown.
39 changes: 39 additions & 0 deletions first30/Exercise 3/count oddeven/firstdigit.py
Original file line number Diff line number Diff line change
@@ -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))












Binary file added first30/Exercise 3/count oddeven/firstdigit.pyc
Binary file not shown.
33 changes: 33 additions & 0 deletions first30/Exercise 3/count oddeven/lengthofpallindrome.py
Original file line number Diff line number Diff line change
@@ -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))
21 changes: 21 additions & 0 deletions first30/Exercise 3/count oddeven/pallindrome.py
Original file line number Diff line number Diff line change
@@ -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))
Binary file added first30/Exercise 3/count oddeven/pallindrome.pyc
Binary file not shown.
17 changes: 17 additions & 0 deletions first30/Exercise 3/count oddeven/test_countoddeven.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions first30/Exercise 3/count oddeven/test_pallindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def test_canassertTrue():
assert True


import pallindrome
def test_pallindrome():
actual=pallindrome.Ispallindrome(1221)
expected=True
assert expected==actual
8 changes: 8 additions & 0 deletions first30/Exercise 3/countinteger/.pytest_cache/README.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
4 changes: 4 additions & 0 deletions first30/Exercise 3/countinteger/.pytest_cache/v/cache/nodeids
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"test_countinteger.py::test_canassertTrue",
"test_countinteger.py::test_countintegerofgivennumber"
]
Binary file not shown.
15 changes: 15 additions & 0 deletions first30/Exercise 3/countinteger/countinteger.py
Original file line number Diff line number Diff line change
@@ -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))
Binary file added first30/Exercise 3/countinteger/countinteger.pyc
Binary file not shown.
8 changes: 8 additions & 0 deletions first30/Exercise 3/digitcounting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#Write a program to count the number of in an integer:


def Digitcounting(N):

count=0


21 changes: 21 additions & 0 deletions first30/Exercise 3/digitdivision.py
Original file line number Diff line number Diff line change
@@ -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))
Binary file added first30/Exercise 3/digitdivision.pyc
Binary file not shown.
24 changes: 24 additions & 0 deletions first30/Exercise 3/ktheven.py
Original file line number Diff line number Diff line change
@@ -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))


13 changes: 13 additions & 0 deletions first30/Exercise 3/reverse.py
Original file line number Diff line number Diff line change
@@ -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))
Binary file added first30/Exercise 3/reverse.pyc
Binary file not shown.
12 changes: 12 additions & 0 deletions first30/Exercise 3/sumofeven.py
Original file line number Diff line number Diff line change
@@ -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))
13 changes: 13 additions & 0 deletions first30/Exercise 3/sumofodd.py
Original file line number Diff line number Diff line change
@@ -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))
25 changes: 25 additions & 0 deletions first30/Exercise 3/sumofsquares.py
Original file line number Diff line number Diff line change
@@ -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))
17 changes: 17 additions & 0 deletions first30/Exercise 3/test_digitdivision.py
Original file line number Diff line number Diff line change
@@ -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

9 changes: 9 additions & 0 deletions first30/Exercise 3/test_reverse.py
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions first30/allprimes.py
Original file line number Diff line number Diff line change
@@ -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)


Loading