March 16 (PYQs of Programming Based Questions by Swati Chawla)
March 16 (PYQs of Programming Based Questions by Swati Chawla)
http://www.youtube.com/swatichawlaofficial
PLACES={1:"Delhi",2:"London",3:"Paris",4:"New
York",5:"Doha"}
def countNow(PLACES):
for i in PLACES:
if len(PLACES[i])>5:
print(PLACES[i].upper())
countNow(PLACES)
L = [10,20,30,10,40]
N=10
def search_replace(L,N):
found=0
for i in range(len(L)):
if L[i]==N:
L[i]=0
found=1
if found==0:
print(N,"Element not exist...")
print(L)
search_replace(L,N)
Method 2
L=[ 123, 10, 13, 15, 23]
def Sum3(L):
S=0
for i in range(len(L)):
if L[i]%10==3:
S=S+L[i]
print("Sum of integers ending with digit 3 =",S)
Sum3(L)
L=[12,4,0,11,0,56]
def INDEX_LIST(L):
indexList=[]
for i in range(len(L)):
if L[i]!=0:
indexList.append(i)
return indexList
R=INDEX_LIST(L)
print(R)
def oddtoeven(L):
for i in range(len(L)):
if L[i]%2!=0:
L[i]=L[i]*2
print(L)
L=[23,4,3,5,1,2]
oddtoeven(L)
GIRlRAJ#
131313
ZARA#
#Method 1
def OddSum(NUMBERS):
S=0
for i in range(len(NUMBERS)):
if i%2!=0:
S=S+NUMBERS[i]
print("Sum of Values at odd position=",S)
NUMBERS=[2,4,5,2,4,5]
OddSum(NUMBERS)
#Method 2
def OddSum(NUMBERS):
S=0
for i in range(1,len(NUMBERS),2):
S=S+NUMBERS[i]
print("Sum of Values at odd position=",S)
NUMBERS=[2,4,5,2,4,5]
OddSum(NUMBERS)
#Method 1
STATES=["MP","UP","WB","TN","MH","MZ","DL","BH","RJ",
"HR"]
def MSEARCH(STATES):
for i in STATES:
if i.startswith('M'):
print(i)
MSEARCH(STATES)
#Method 2
def MSEARCH(STATES):
for i in STATES:
if i[0]=='M':
print(i)
MSEARCH(STATES)
SCORES=[205,506,365,100,230,335]
def Endingwith5(SCORES):
S=0
for i in SCORES:
if i%10==5:
S=S+i
print(S)
Endingwith5(SCORES)
REGIONS=["GOA","NEW
DELHI","DAMAN","CHENNAI","BANGALORE"]
def COUNTNOW(REGIONS):
for i in REGIONS:
if len(i)<=5:
print(i)
COUNTNOW(REGIONS)
Names=["Arun","Raj","Tarun","Kanika"]
HisName="Aman"
def FindOut(Names, HisName):
found=0
for i in range(len(Names)):
if Names[i]==HisName:
print(HisName,'at',i)
found=1
if found==0:
print("Sorry,",HisName,'not exist.')
FindOut(Names,HisName)
def TenTimesEven(VALUES):
S=0
for i in VALUES:
if i%2==0:
S=S+i*10
print("Even Sum:",S)
Nums= [5,2,3,6,3,4]
TenTimesEven(Nums)
#Method 1
def EndingA(Names):
for i in Names:
if i.endswith('A'):
print(i)
Names=["JAYA", "KAREEM", "TARUNA", "LOVISH"]
EndingA(Names)
#Method 2
def EndingA(Names):
for i in Names:
if i[-1]=='A':
print(i)
Names=["JAYA", "KAREEM", "TARUNA", "LOVISH"]
EndingA(Names)
values in it
For Example:
If the list Numbers contain
[35,67,89,23,12,45]
After swapping the list content should be displayed
as
[23,12,45,35,67,89]
def Swapper(Numbers):
mid=len(Numbers)//2
for i in range(0,mid):
Numbers[i],Numbers[mid+i]=Numbers[mid+i],Numbers[i]
print(Numbers)
Numbers=[35,67,89,23,12,45]
Swapper(Numbers)
def LShift(Arr,n):
L=len(Arr)
for x in range(0,n):
y=Arr[0]
for i in range(0,L-1):
Arr[i]=Arr[i+1]
Arr[L-1]=y
print(Arr)
Arr=[10,20,30,40,12,11]
n=2
LShift(Arr,n)