You are on page 1of 15

Mettl Programs

Day_4 :thursday (17-2-2022)

----------------------------------------------------------

1. Given 5 numbers, How many odd or even

#My method:

def count(input1,input2,input3,input4,input5,input6):

oc=0

ec=0

if input1%2==0:

ec+=1

else:

oc+=1

if input2%2==0:

ec+=1

else:

oc+=1

if input3%2==0:

ec+=1

else:

oc+=1

if input4%2==0:

ec+=1
else:

oc+=1

if input5%2==0:

ec=+1

else:

oc+=1

if input6=="odd": return ec

return oc

#Actual code:

cnt=0

data=[input1,input2,input3,input4,input5]

if(input6="even"):

for i in data:

if(data[i]%2==0):

cnt+=1

return cnt

else:

if(input6=="odd"):

for i in data:

if(data[i]%2!=0):

cnt+=1

return cnt

----------------------------------------------------------------------
Day_5:Friday(18-02-2022)

1.

#inpu=abs(input1)

while (input1>9):

sum_value=0

while(input2>0):

sum_value +=inpu%10

inpu //=10

inpu=sum_value

if (inpu1<0):

return -inpu

else:

return inpu

'''

odsum=0

sum_value=0

while input1>0:

dig=input1%10

sum_value+=digit

if(dig)%2!=0:

odsum+=dig

input1=input1//10
if input2.lowe()=="even":

return(sum_value - odsum)

elif input2.lowe()=="odd":

return(odsum)

else:

return("write correct input2")

'''

Actual method:Even or Odd digit sum

1.summ=0

if input2=="even":

while input1>0:

r=input1%10

if r%2==0:

summ=summ+r

input1=input1//10

return summ

if input2=="odd":

while input1>0:

r=input1%10

if r%2==1:

summ=summ+r

input1=input1//10

return summ
2. DigitSum:

inpcopy=input1

str3=str(inpcopy)

while(input1>0 or input1<0):

sum=0

str1=str(input1)

str=str.replace("-","")

for i in str1:

sum=sum+int(i)

str2=str(sum)

if len(str2)==1:

if(str3._contains_('-')):

return int("-"+str2)

else:

reurn(str2)

break

else:

input1=sum

3.Fibonacci series:

a=0

b=1
if input1 ==1:

return a

count = 2

while count<input1:

a,b = b, a+b

count +=1

return b

4.Array Odd or even Processing

n=[]

for i in input1:

if i%2==0:

n.append(i+2)

else:

n.append(i+1)

return n

5.Sum of digits in cyclic order

**********************************************************************************
***********************
1.Even or odd digit sum

first parameter:number like 9625

second parameter :"odd"

o:p is 14

input1=9625

input2="odd"

sum=0

if input2=="even":

str1=str(input1)

for i in str1:

if (int(i)%2==0):

sum=sum+i

return sum

elif input2=="odd":

str1=str(input1)

for i in str1:

if (int(i)%2!=0):

sum=sum+i

return sum

***************************

2.single digitcount

ex:123456-->[1+2+3+4+5+6]=21

[2+1]=3

output:3
inp=-976592

inpcopy=inp

str3=str(inpcopy)

while(inp>0 or inp<0):

sum=0

str1=str(inp)

str1=str1.replace("-","")

for i in str1:

sum=sum+int(i)

str2=str(sum)

if len(str2)==1:

if (str3.__contains__('-')):

print int(("-"+str2))

else:

print int((str2))

break

else:

inp=sum

------------------

i=-976592

str1=str(i)

j=int(str1.replace('-',''))

if j==0:

print("0")

if(j%9==0):

if (str1.__contains__('-')):
print(-9)

else:

print(9)

else:

if (str1.__contains__('-')):

print(-(j%9))

else:

print(j%9)

*******************************************************

3.nth fibonacci sequence

n1=0

n2=1

n=10

for i in range(1,n):

temp=n1+n2

n1=n2

n2=temp

print(n1)

************************************************************

4.input1=[101,56,23]

input2=3

if even number add "2" odd number add "1"

o:p/[102,58,24]

input1=[101,56,23]
n=[]

for i in input1:

if i%2==0:

n.append(i+2)

else:

n.append(i+1)

print(n)

**********************************************************

5.

input1 is 582109=(5 + 8 + 2 + 1 + 0 + 9) + (8 + 2 + 1 + 0 + 9) + (2 + 1 + 0 + 9) + (1 + 0 + 9) + (0 + 9) + (9)

= 25 + 20 + 12 + 10 + 9 + 9 = 85

string = str(input1)

cyStringInd = 0

sumVal = 0

while cyStringInd<len(string):

cyString = string[cyStringInd:len(string)]

for i in cyString:

sumVal += int(i)

cyStringInd += 1

return sumVal

--------------------------------------------------------------------------------------------------------------------------
Day_7:Tuesday(22-02-2022)

#1.

'''

def sumOfPowerOfDigits(cls,input1):

sumVal = 0

num = input1

ld = 0

while num>0:

sumVal += pow(num%10,ld)

ld = num%10

num //=10

return sumVal

'''

#2.

'''

#Method 1:

def isPalindrome(cls,input1):

rev=""

for i in input1:

rev = i+rev

if rev.lower()==input1.lower():

return 2

else:

return 1
#Method 2:

def isPalindrome(cls,input1):

newStr = ""

for i in range(len(input1)-1, -1, -1):

newStr += input1[i].lower()

print(newStr)

if newStr == input1.lower():

return 2

else:

return 1

'''

#3.

'''

def MostFrequentDigit(cls, input1, input2, input3, input4):

DigCount = dict()

for i in str(input1):

if int(i) in DigCount:

DigCount[int(i)] += 1

else:

DigCount[int(i)] = 1

for i in str(input2):

if int(i) in DigCount:

DigCount[int(i)] += 1

else:
DigCount[int(i)] = 1

for i in str(input3):

if int(i) in DigCount:

DigCount[int(i)] += 1

else:

DigCount[int(i)] = 1

for i in str(input4):

if int(i) in DigCount:

DigCount[int(i)] += 1

else:

DigCount[int(i)] = 1

maxOcc = -1

maxKey = -1

for Key in DigCount:

if key>maxKey and DigCount[Key]>=maxOcc:

maxKey = Key

maxOcc = DigCount[Key]

return maxKey

'''

#4.

'''

def totalHillWeight(cls, input1, input2, input3):

wt = 0

for i in range(1,input1+1):
wt = wt + input2*i

input2 = input2 + input3

return wt

'''

#5.

'''

def WeightOfStringCode(cls, ):

string = input1.lower()

vow = []

con = []

for i in string:

if(ord(i)>96 and ord(i)<123):

if(ord(i) == 97 or ord(i) == 101 or ord(i) == 105 or

ord(i) == 111 or ord(i) == 117):

vow.append(ord(i) - 96)

else:

con.append(ord(i) - 96)

if(input2==1):

return sum(vow+con)

elif(input2==0):

return sum(con)

'''

You might also like