Skip to main content

Posts

mysql connector

import mysql.connector import datetime mydb=mysql.connector.connect(host="localhost",\                              user="root",\                              passwd="root",\                              database="practicalexam") mycursor=mydb.cursor() def teacheradd():     L=[]     tno=int(input("Enter tno:"))     L.append(tno)     tname=input("Enter tname:")     L.append(tname)     tsalary=int(input("Enter tsalary:"))     L.append(tsalary)     value=L     value=(tno,tname,tsalary)     sql="insert into teacher(tno,tname,tsalary)values(%s,%s,%s)"     mycursor.execute(sql,value)     mydb.commit() def teachersearch():   ...
Recent posts

queue

a=[] c= "y" while(c=="y"):     print("1. INSERT")     print("2. DELETE")     print("1. DISPLAY")     choice=int(input("Enter Your Choice:"))     if(choice==1):         b=input("Enter new number:")         a.append(b)     elif(choice==2):         if(a==[]):              print("Queue is Empty")         else:             print("Deleted value is:",a[0])             a.pop(0)     elif(choice==3):         length=len(a)         for i in range(0,length):      ...

stack

s=[] c="y" while(c=="y"):     print("1. PUSH")     print("2. POP")     print("3. DISPLAY")     choice=int(input("Enter your choice"))     if(choice==1):         a=input("Enter any number: ")         s.append(a)     elif (choice==2):         if(s==[]):             print("Stack Empty")         else:             print("Element Deleted is :",s.pop())      elif(choice==3):         l=len(s)         for i in range(l-1,-1,-1):             print(s[i])     else:  ...

pallindrome recursive

def isStringPalindrome(str):     if len(str)<=1:         return True     else:         if str[0]==str[-1]:             return isStringPalindrome(str[1:-1])         else:             return False #__main__ s=input("Enter the string : ") y=isStringPalindrome(s) if y==True:     print("String is Palindrome") else:     print("String is Not Palindrome")

linear search

def Lsearch(ar,item):     i=0     while i<len(ar) and ar[i]!=item:         i=i+1     if i<len(ar):         return i     else:         return Flase N=int(input("Enter total numbers of the list")) print("\nEnter elements for the list\n") ar=[0]*N     #initialize list of size N with zero for i in range(N):     ar[i]=int(input("Element"+str(i)+":")) item=int(input("Enter element to be searched")) index=Lsearch(ar,item) if index:     print("Element found at", index+1) else:     print("Element not found")

tylor series

import math def fact(k):     if k<=1:         return 1     else:         return k*fact(k-1)     step=int(input("How many terms : ")) x=int(input("Enter the value of x :")) sum=0 for i in range(step+1):     sum+=(math.pow(-1,i)*math.pow(x,2*i+1))/fact(2*i+1) print("The result of sin",'(', x, ')', "is :", sum)

binary search recursive

def binsearch ( ar,key,low,high ):     if low>high:         return -999       #Base Case     mid= int (( low+high )/2)     if key== ar [mid]:         return mid        #Base Case     elif key< ar [mid]:         high=mid-1         return binsearch ( ar,key,low,high )     else:         low=mid+1         return binsearch ( ar,key,low,high ) ary =[13,15,17,19,21,23,34,36,45] item= int (input("Enter no. to search:")) res= binsearch (ary,item,0,len( ary )-1) if res>=0:     print( item,"Found at index",res ) else:     print("Number not found")