Posts

Showing posts from December, 2021

Counting time taken for programme in python

#Python 3.7.5 import time,math t=time.clock() print(math.factorial(5)) t2=time.clock()-t print("Time taken is ",t2) NOTE: From python 3.8 onwards use time.perf_counter() #Python 3.8 import time,math t=time.perf_counter() print(math.factorial(5)) t2=time.perf_counter()-t print(t2)

SEO-1

  What is SEO? How to do SEO? SEO (Search Engine Optimization) Search engine optimization, or SEO, is a strategy for improving your site’s rankings in search engine results. The top 5 search engines are, ·          Google. ·          Bing. ·          Baidu. ·          Yahoo! ·          Yandex.   What happens when a search is performed? In addition to the search query entered by a user in search engine, search engines use other relevant data to return results, including: ·          Location – Some search queries are location-dependent e.g. ‘cafes near me’ or ‘movie times’. ·          Language detected – Search engines will return results in the language of the user, if it can b...

Sudoku using BackTracking

Image
Backtracking means switching back to the previous step as soon as we determine that our current solution cannot be continued into a complete one. M = 9 def puzzle(a):     for i in range(M):         for j in range(M):             print(a[i][j],end=" ")         print()          def solve(grid, row, col, num):     #Row wise check if num is there     for x in range(9):         if grid[row][x] == num:             return False     #column wise check if num is there              for x in range(9):         if grid[x][col] == num:             return False       #check if num is in 3*3 grid     startRow = row - row % 3      startCol = col - col % 3      for i in range(3): ...

solving MAZE using python

   #Maze dimensions 8*13  def print_maze(maze):     for row in maze:         for item in row:             print(item, end='')         print()       def find_start(maze):     for row in range(len(maze)): #len of maze is 8         for col in range(len(maze[0])): #col=13             if maze[row][col] == 'S':                 return row, col  #row=1,col=0 # This is function tells if we have a valid position. def is_valid_position(maze, pos_r, pos_c):     if pos_r < 0 or pos_c < 0:         return False     if pos_r >= len(maze) or pos_c >= len(maze[0]):         return False     if maze[pos_r][pos_c] in ' E':         return True     return False #ALGORITHM def solve_maze(m...

Testing Dummy post

This is a dummy post from email.  Just to check if it is working...

GUI

  Graphical User Interface with Tkinter Tkinter is an open source , portable GUI available  in python 2.x and 3.x versions. Tkinter supports all platforms(Windows,Mac,Linux) Tkinter module is available by default with python IDLE. How to create a GUI window?(3.7) import tkinter as tk root=tk.Tk() root.mainloop() configure() Used for configuring widgets with options like background color , borderwidth.... Syntax:    <widget>.configure(option=value) Example import tkinter as tk root=tk.Tk() root.configure(background="red") root.mainloop() Layout Managers Tkinter has the following layout managers. 1.pack() 2.grid() 3.place() We should never mix one layout manager with another. 1.pack() This layout manager arranges widgets in a stack order. Label() This will create a label syntax:       Label(parent,text="labelled text") Button() This will create  a button Syntax:      Button(parent,text="Button text") Entry()  This will crea...

Testing

 Testing article 2

Regular Expressions

 Regular expressions -------------------- These are mainly used for pattern matching. These are used for validating data based on the  given patterns. A regular expression is a group of special characters which is used for matching a pattern. For example, \d is used for matching numbers(0-9) To use regular expression, we import the module re. And it has the following functions: 1.match(pattern,data,flags):   Matches the given pattern at the begining on the given data.   If it matches , it will return the matched object otherwise it will return None. 2.search(pattern,data,flags):   This function matches the pattern on the given data at begining or at ending or at middle.   If it matches , it will return the matched object otherwise it will return None. 3.group():    Is used for returning matched data from matching  object Example ======= import re result= re.match("Apple","Apple Computers ") if result:     print("Matched data is ",re...

Iterators and Generators

 Iterators An iterator is an object that can be iterated. Iterator return only one element at a time. Iteator has 2 special methods: 1.__iter__()                      Returns the iterator object 2.__next__()                      Returns the current item.                      Move to the next iteration. Example L=iter([10,20]) #iter() #print(L.__next__()) print(next(L)) print(next(L)) print(next(L)) #stopIteration Error Example2 Make an iterator of 2 power values upto 5 (2^0  2^1  2^2  2^3 2^4  2^5) class PowerTwo:     def __init__(self,max):         self.max=max     def __iter__(self):         self.n=0         return self     def __next__(self):         if self.n<=self.max: #0<=5...