0% found this document useful (0 votes)
9 views15 pages

Accenture Codes

Uploaded by

Soniya Shaik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views15 pages

Accenture Codes

Uploaded by

Soniya Shaik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Accenture Codes

1.Triple Product count:


Sample Input:
N=12
S=5
l=[2,3,6,1,4]
Sample Output:
2
Explanation:
Here N is the product of three elements in the list. S is the size. l is
the list.
[2,6,1]=2*6*1=12
[3,1,4]=3*1*4=12.
So count is 2
Source code:
from itertools import combinations
n=int(input())
s=int(input())
l=list(map(int,input().split()))
c=combinations(l,3)
count=0
for i in list(c):
p=1
for j in i:
p=p*j
if p==n:
count+=1
print(count)
2.Counting indices:
Sample input:
5
23574
Sample output:
4
Explanation:
2 is even and index (0) is even. (True)
3 is odd and index (1) is odd. (True)
5 is odd and index (2) is even. (False)
7 is odd and index (3) is odd. (True)
4 is even and index (4) is even. (True)
So count is 4.

Source Code:
n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(0,len(a)):
if (i%2==0 and a[i]%2==0) or (i%2!=0 and a[i]%2!=0):
c+=1
print(c)
3.Rotate words in string
Sample Input:
19
abcd efgh ijkl mnop
2
Sample output:
Ijkl mnop abcd efgh
Explanation:
Here 19 is the number of characters and 2 is the rotation number of
the words. 2 words rotate and then output is like Ijkl mnop abcd
efgh.
Source Code:
n=int(input())
s=input()
r=int(input())
l=s.split()
a=r%len(l)
l=l[a:]+l[:a]
print(' '.join(l))
4.Detecting perfect numbers
Sample Input:
6
Sample Output:
1
Explanation:
6 factors are 1,2,3.
1+2+3==6.
So output is 1.

Source Code:
n=int(input())
s=0
for i in range(1,n):
if n%i==0:
s=s+i
if s==n:
print("1")
else:
print("0")
5.Googly number
Sample Input:
12
Sample output:
GOOGLY
Explanation:
Sum of digits of 12 is 1+2=3 which is a prime number. Then it is
googly number.
Source Code:
def prime(n):
c=0
for i in range(1,n+1):
if n%i==0:
c+=1
if c==2:
return 1
else:
return 0
n=int(input())
s=str(n)
sum=0
for i in s:
sum=sum+int(i)
if prime(sum):
print("GOOGLY")
else:
print("NOT GOOGLY")
6. Most Frequent vowel
Sample Input:
aaabcce
Sample Output:
a
Explanation:
a is occurred three times which is the maximum occurring vowel.
Source code:
s=input()
d={}
for i in s:
if i in "aeiou":
d[i]=d.get(i,0)+1
m=max(d.values())
l=[]
for key,values in d.items():
if values==m:
l.append(key)
print(l[0])
7.Sum of circular primes in a range
Sample Input:
60
80
Sample Output: 223
Explanation:
The prime numbers between 60 and 80 are (61,67,71,73,79). Prime
numbers 71, 73 and 79 are circular prime because their rotation 17,
37 and 97 respectively, are also prime. Thus, the sum of (71,73,79) is
223.
Source Code:
from itertools import permutations
def prime(n):
c=0
for i in range(1,n+1):
if n%i==0:
c+=1
a=1 if c==2 else 0
return a
rangeMin=int(input())
rangeMax=int(input())
l=[]
for i in range(rangeMin,rangeMax+1):
if prime(i):
l.append(i)
l1=[]
for i in l:
a=list(str(i))
b=0
p=permutations(a,len(a))
c1=0
for j in set(p):
b+=1
if prime(int(''.join(j))) and int(''.join(j)) not in l:
c1+=1
if c1==b-1:
l1.append(i)
print(sum(l1))

8.Value of cards
Source code:
a=int(input())
b=int(input())
c=int(input())
d=int(input())
z={11:3,9:2,10:1,1:1}
s=0
if a in z:
s+=z[a]
if b in z:
s+=z[b]
if c in z:
s+=z[c]
if d in z:
s+=z[d]
print(s)
9. Sum of uncommon elements
Source Code:
n1=int(input())
n2=int(input())
a1=set(list(map(int,input().split())))
a2=set(list(map(int,input().split())))
if n1==0 and n2==0:
print("-1")
else:
s=0
x=a1-a2
y=a2-a1
print(sum(x)+sum(y))
10. Odd or Even sum
Source Code:
dice=int(input())
n=list(map(int,input().split()))
o=0
e=0
for i in range(len(n)):
if i%2==0:
o+=int(n[i])
else:
e+=int(n[i])
if dice%2==0:
print(o)
else:
print(e)
11. Prefix Suffix
Source Code:
n=int(input())
s=input()
if len(s)==0:
print("-1")
else:
i=len(s)//2
while s[:i]!=s[-i]:
i-=1
print(i)
12. Number with maximum occurrence of
digit k.
Source Code:
n=int(input())
k=int(input())
l=[]
if k==0:
print("-1")
else:
l1=list(map(int,input().split()))
for i in range(k):
a=str(l1[i])
l.append(a.count(str(n)))
if l.count(0)==len(l1):
print("0")
else:
i=l.index(max(l))
print(l1[i])
13. Primes in range
Source code:
def prime(n):
count=0
for i in range(1,n+1):
if n%i==0:
count+=1
if count==2:
return 1
else:
return 0
n=int(input())
c=0
i=1
while c!=n:
if prime(i):
c+=1
i+=1
print(i-1)
14. What & 39’s missing
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
for i in a:
if i not in b:
print(i)
for i in b:
if i not in c:
print(i)
15. Convert to palindrome
Source Code:
n=int(input())
s=input()
a=""
i=0
temp=s
while s!=s[::-1]:
if s[i]!=s[len(s)-1-i]:
a=a+s[i]
s=temp+a
i+=1
print(a)

You might also like