Skip to main content

Posts

Showing posts with the label Python

Program in Python: Insertion Sort

Program in Python: Insertion Sort l=[] n=int(input("enter the number of elements")) print("enter",n,"elements into the list") for i in range(n):  m=int(input("enter number:"))  l.append(m) for i in range(1,n):  key=l[i]  j=i-1  while j>=0 and key < l[j]:   l[j+1]=l[j]   j=j-1  else:      l[j+1]=key print("list after sorted",l) Insertion sort ascending order

Program in Python: Bubblesort

L = [] #empty list n = int(input("Enter the number of elements: ")) print("Enter",n,"elements into the list") for i in range(n):     m = int(input("Enter number: "))     L.append(m) for i in range(0,n-1):     for j in range(0,n-i-1):         if L[j]>L[j+1]:             L[j],L[j+1]=L[j+1],L[j] print("The sorted elements: ") print(L)

Python Dictionary Notes

 Dictionary (Back to basics) Definition: 1) Dictionaries are used to store data in key-value pair form.      'name' : 'Lamborghini'   so the 'name' is the key and 'Lamborghini' is the value.    2) A dictionary is a collection of ordered(in Python 3.7 or later) and unordered(in Python 3.6 or earlier). It does not allow duplicates.  for example:  {'name':'Bugatti','name':'Buggati' } not possible due to duplicate key value pair  or  {'name':'Alfa Romeo','name':'Maserati'} not possible due to duplicate key and if used then the second key-value pair is displayed instead of the first item. 3) Dictionaries are written within curly brakets and have key-value pairs        car = {'brand':'Ford','model':'Mustang','year':1964}    print(car) 4) Dictionary length - it determines how many items a dictionary has using the len() function. It is important to note that...

File Handling Python Notes

 File Handling File are of two types: (i) Text file: are files which are ascii converted files. Example: csv(comma separated values),tsv(tab separated values) and txt(text files) (ii) Binary files: are file which raw digital data taken from input interface without any ascii convertion. Example: Any msoffice file(example .docx,.pptx,.xlsx etc) , bin(binary file), dat(data file) EOL : End of file. It is an character which marks the end of file or text document. It generally noted as '\n\r' . \n means new line and \r means return(basically enter key) To open a file: we use open() function. It takes three parameters : (i) path: It takes two kinds of path. (a) raw path: where you need to add r alphabet before the path name enclosed within single quote or double quote  example:  f = open(r'C:/info/value.txt') (b) absolute path: where you need to pass the path with escape sequences \\.  f= open('C://info//value.txt') (ii) mode: The default mode of open() functio...

Python program to display the short form of a sentence

Python program to display the short form of a sentence 

Python Program to display the list of palindrome words in a sentence

 Python Program to display the list of palindrome words in a sentence 

Frequency of vowels in a string python

Python MySQL CRUD Program

 Create python program to create,read,update and delete student details in MySQL database import mysql.connector as p con = p.connect(host="localhost",user="root",passwd="1234",database="useless") if con.is_connected():     print("Connection Established")     cur = con.cursor()     while True:         print("Enter 1 to add new student")         print("Enter 2 to update student details")         print("Enter 3 to delete student")         print("Enter 4 to show student list")         print("Enter 5 to exit system")         ch = int(input())         if ch==1: #insert data into table             ids = int(input("Enter the student id:"))             name = input("Enter the student name:")             cls = int(input("Enter student ...