Skip to main content

REVISION LIST PRACTICE - 21 AUG

 

REVISION LIST PRACTICE 

GRADE XI


1.#LINEAR SEARCH/search for an element in a given list

list1=eval(input("Enter the List elements"))

length=len(list1)

element=int(input("Enter the element to be searched for")) 

for i in range(0,length):

    if element==list1[i]:

        print("Element found At Index:",i)

        break

else:

    print(element,"Not present in the list")


2.#[45,66,20,77,20]

#REPLACE [ALL 2 WITH 20 IN A LIST]

a=[1,2,2,1,4,5,1]

for i in range(len(a)):

    if a[i]==2:

        a[i]=20

print(a)


3. #PROGRAM TO CALCULATE MEAN OF A GIVEN LIST NUMBERS

list1=eval(input("Enter the List elements"))

length=len(list1)

mean=sum=0

for i in range(0,length):

    sum+=list1[i]

mean=sum/length

print("Given List is:",list1)

print("Mean of Given List is:",mean)


4.#ADDITION OF ELEMENTS

list1=[4,5,6,6]

list2=[1,2,3,4]

print("ORIGINAL LIST1 IS:"+str(list1))

print("ORIGINAL LIST2 IS:",list2)

res_list=[]

for i in range(0, len(list1)):

    res_list.append(list1[i]+list2[i])

print("The resultant List is :"+str(res_list))


5#Program to input a list and to count number of #non-numeric data in a list

list=[]

s = int(input("Enter no of elements - "))  

for i in range(s):

    list+=[eval(input("Enter the element - "))]  

print(list)

ctr=0

for i in range(s):

    if type(list[i])==str:

           ctr+=1

print("no. of non-numeric data - ",ctr)


6#Find Max number in a given list

list=[1,20,30,87,34]

max = list[0]

for a in list:

    if a > max:    

        max = a

    print(max)

Comments

Popular posts from this blog

CS - SORTING/SEARCHING ALGORITHMS

  SORTING ALGORITHMS                       SORTING ALGORITHM PDF LINK #Bubble Sort          ·        The outer loop iterates through the entire array. ·        The inner loop compares adjacent elements and swaps them if they are out of order. ·        The outer loop runs n times, and each pass moves the largest element to its correct position. arr=[3,8,5,2,1] n = len(arr) print(n) for i in range(n):  #traverse through all the elements         # Last i elements are already sorted, no need to check them         for j in range(0, n-i-1):              # Swap if the element found is greater than the next element              if arr[j] > arr[j+1]:               ...

PYTHON - MYSQL CONNECTIVITY CODE

  #INSERTION OF DATA import mysql.connector mydb = mysql.connector.connect( host="localhost", user="root", passwd="root", database="school" ) print("Successfully Connected") #print(mydb) mycursor=mydb.cursor()   v1=int(input("enter ID:")) v2=input("enter name:") v3=input("enter Gender:") v4=int(input("enter age:")) sql='insert into TEACH values("%d","%s","%s","%s")'%(v1,v2,v3,v4) print(sql) mycursor.execute(sql) mydb.commit() print("record added") #MYSQL Connection code – Deletion on database SOURCE CODE: s=int(input("enter id of TEACHER to be deleted:")) r=(s,) v="delete from TEACH where id=%s" mycursor.execute(v,r) mydb.commit() print("record deleted") MYSQL Connection code – Updation on database SOURCE CODE: import mysql.connector mydb = mysql.connector.c...