Practises

You might also like

You are on page 1of 7

Program1

Given a string “Eat sleep rave repeat”


If 1st and last characters are special chars then add A to output string.
Otherwise,If 4th character is number then add B to output string.
Otherwise,If there is exactly 3 special characters in the given sring
then add C to output string.
Otherwise,If there are 4 words in the string then add D to output string.
Otherwise,If there are all the five vowels in the string then add E to
output string.
If no condition is satisfied then add X to output string.
N="Eat sleep rave repeat"
ANSWER:
N="Eat sleep rave repeat"

def fun(N):
count=0
count1=0
count2=0
v="aeiou"

for i in N:
if (i.isspace()):
count1=count1+1
for i in N:
if not (i.isalnum() or i.isspace()):
count=count+1
for i in v:
if (i in N):
count2=count2+1

if not (N[0].isalnum() or N[-1].isalnum()):


return "A"
elif (N[3].isdigit()):
return "B"
elif (count==3):
return "C"
elif (count1==3):
return "D"
elif (count2==5):
return "E"
else:
return "X"

print(fun(N))
-------------------------------------------------------------------------
-------------------------------------------------------
Program2

Given a string – Str=”I lov3e myself”


Output=”B” Conditions:
1. If it has exactly 3 different special chars then add A to output.
2. Otherwise,If it has a digit on 2nd word at any position then add B to
output.
3. Otherwise,If the numberof chars is greater than 50 then add C to
output string.(Chars contains spaces also)
4. Otherwise,If there is a coma(,) in the sentence then add D
5. Otherwise, If first character is not capital then add E.
If none of the conditions is satisfied then return -1
ANSWER:
Str="I lov3e myself"
output=""

def fun(Str):
count=0
count1=0
count2=0
a=Str.split()
b=a[1]

for i in Str:
if not (i.isalnum() or i.isspace()):
count+=1
for i in b:
if (i.isdigit()):
count1+=1
for i in Str:
if (i in ","):
count2+=1
if (count==3):
return "A"
elif (count1>=1):
return "B"
elif (len(Str)>50):
return "C"
elif (count2>0):
return "D"
elif (Str[0].islower()):
return "E"
else:
return "-1"
print(fun(Str))
-------------------------------------------------------------------------
-------------------------------------------------------------------------
--
Program3
Given two lists of numbers
L1=[12,23,45,67,89]
L2=[92,83,75,87,59]
Output=[]
Conditions:
1.If the number in l1is present in l2 then add this number to output
list.
2.If the reverse of the number of l1 is present in l2 then add this
number to output.
3.If square of the number in l1 is present in l2 then add this number to
output list.
4.Print outputlist.
ANSWER:
L1=[12,23,45,67,89]
L2=[92,83,75,87,59]
Output=[]
L3=[]
rev=""
rev1=""

for i in L1:
for j in L2:
if (i==j):
Output.append(i)
for i in L1:
rev=str(i)
rev1=rev[::-1]
L3.append(int(rev1))
for i in L2:
if (i in L3):
Output.append(i)
for i in L1:
for j in L2:
if(j==i*i):
Output.append(j)
print(Output)
-------------------------------------------------------------------------
-----------------------------------------------
Program4
Given two lists of numbers
L1=[12,23,45,67,89]
L2=[92,83,75,87,59]
Output=C
Conditions:
1.If l1 is exactly same as the l2 then add A to output string.
2.Otherwise,If exactly 2 numbers of l1 is present in l2 then add B to
output string.
3.Otherwise,If last digit of corresponding numbers are same then add C to
output string.
4.Otherwise,If sum of all elements of l1 is present in l2 as an element
then add D to output string.
5.If none of the above conditions satisfied then add E to output string.
ANSWER:
L1=[12,23,45,67,89]
L2=[92,83,75,87,59]
Output=""
count=0
count1=0
s=0
if(L1==L2):
Output="A"
for i in L1:
for j in L2:
if (i==j):
count1+=1
for i in L1:
s+=i
for j in L2:
if(j==s):
count+=1
if(count1==2):
Output="B"
for i in L1:
for j in L2:
if(i%10==j%10):
Output="C"
if(s in L2):
Output="D"
if (Output==""):
Output="E"
print(Output)

-------------------------------------------------------------------------
-----------------------------------------------
PROGRAM -5
1.If count of @ is greater than 1 append…...
2.If given string ends with Gmail.com append……
3.If count of vowels is greater than 1 append…….
4.If in the given string digits are present append count of digits in
output string.
inp="yamininandam123@Gmail.Com"
output=""
ANSWER:
inp="yamininandam123@Gmail.Com"
output=""
count=0
count1=0
count2=0
vow="aeiouAEIOU"

for i in inp:

if (i=="@"):

count+=1

if(count>1):

output+="......"

if(inp.endswith("Gmail.Com")):

output+="...."
for i in vow:

for j in inp:

if(i==j):

count1+=1
if(count1>1):

output+=".."

for i in inp:

if(i.isdigit()):

count2+=1
output+=str(count2)

print(output)
-------------------------------------------------------------------------
-----------------------------------------------
PROGRAM -6
1.If I is present more than once then generate otp as 5
2.If @ is followed by any number then generate otp as 6
3.If 1st and last letter is same then generate otp as 7
4.If there are more than 2 numbers then generate otp as 8
5.If the string ends with .in then generate otp as 9
6.If none of the condition is satisfied then generate otp as 50
inp="yamnnandam@Gmail.Com"
otp=int
ANSWER:
inp="nimmallen.i@infosys.com"
otp=""
count=0
count1=0
a=inp.split("@")
b=a[0]
c=b[-1]
for i in inp:
if ("I" in inp):
count=count+1
for i in inp:
if (i.isdigit()):
count1=count1+1

if (count>1):
otp="5"
elif (c.isdigit()):
otp="6"
elif (inp[0]==inp[-1]):
otp="7"
elif (count1>2):
otp="8"
elif (inp.endswith(".in")):
otp="9"
else:
otp="50"
print(otp)
-------------------------------------------------------------------------
-----------------------------------------------
PROGRAM-7
Input string= Aayusha123456
Condition:last 6 character of input string is empno and like remaining is
empname
1.If starting and ending character of empname is same then append length
of empname in output string.
2.Add all the digits of empno, and if addition is multiple of 2, then
append addition to output string.
3.If 1st two characters of empname is same append small a to output
string.
4.If in empno last 2 digit are same then append that digit to output
string
5.If output string is empty then append output string by F
ANSWER:
Input_string="Aayusha123456"
out=""

name=Input_string[:7]
number=Input_string[-6:]
su=0
if(name[0]==name[-1]):
out+=str(len(name))

if(name[0]==name[1]):
out+="a"
if(number[-2]==number[-1]):
out+=number[-1]
if (out==""):
out+="F"
for i in number:
su+=int(i)
if(su%2==0):
out+=str(su)
print(out)
-------------------------------------------------------------------------
-----------------------------------------------
PROGRAM-8
While setting password you have to determine its strength and by default
strength is 10.
Now given below are the points which tells what strength will be if that
password contains mentioned format:
1.If length is greater than 6 then increase strength by 2 else decrease
by 1
2.If it contains any digit then increase it by 3.
3.If it has any vowel in small case then increase by 2
4.If it has alphabet [A-Z] then increase it by 3
5.If it has any special character among these @,#,&,*,? Then increase by
2
If no condition passes then program should return not a good password.
Password=""
Strength=10
ANSWER:
Password="Itz_Me_h1ere@"
Strength=10
v="aeiou"
alp="QWERTYUIOPLKJHGFDSAZXCVBNM"
count=0
count1=0
count2=0
count3=0
for i in Password:
for j in v:
if (i==j):
count+=1
for i in Password:
if (i in "@#&*?"):
count1+=1
for i in Password:
for j in alp:
if (i==j):
count2+=1
for i in Password:
if (i.isdigit()):
count3+=1

if (count3>=1):
Strength+=3
if (count>=1):
Strength+=2
if(count1>=1):
Strength+=2
if(count2>=1):
Strength+=3
if (len(Password)>6):
Strength+=2
else:
Strength-=1
if (Strength==10)
Strength="not a good password"
print(Strength)

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

You might also like