Posts

training day 9

                                Programs in python Program for reversed string s = input("Enter the string : ") def reverse(s):   s = " " , join(reversed(s))    return s print("The original string is :") print(s) print("The reversed string is :") print(reverse(s)) Program to reverse a string using classes class string : def __init__(self,s):     self.string = s def reverse(self):     st = " ".join(reversed(self.string))    return st x = string("Hello") print(x.reverse())  Program to find area and perimeter of a circle class circle: def __init__(self,r):   self.radius = r def area(self): print("Area of circle") Area = 3.14*self.radius*self.radius  return area def peri(self): print("Circumference of circle ") peri = 2*3.14*self.raduis return peri x = circle(5) print(x.area()) pr...

training post 8

                                  Inheritance in Python class Person:   def __init__(self,fname,lname):          self.firstname = fname          self.lastname = lname def printname(self)      print("First name = " + self.firstname + " lastname" + self.lastname) class student(Person):    X = Pass student("Parneet Kaur")    X.printname() When we do not want anything in our derive class, we use keyword pass. Example :  class person:    def __init__(self,fname,lname):               self.firstname = fname               self.lastname = lname    def printname(self):        print("Firstname = " + self.firstname + "lastname = " + self.lastname) class student(P...

training day7

                               Classes In Python Constructor in python  by default it is pre- defined that is __init__( ) Example : class persons: def __init__(self,name,age);       self.name =  name       self.age = age p1 = persons("John",30)  print(p1.name) print(p1.age) Self is the reference to current instance of class. We can access variables belonging to class using self keyword. Example :  def __init__(self,name,age):     self.name = name     self.age = age def myfunction(self):    print("Hello! my name = " + self.name + " and age = " + self.age) p1.persons("John",30) p1.myfunction() we can write anything instead of self, but first parameter will always be a the instance. If we want to delete any variable from class class person: def __init__(self,name,age): ...

training day6

                                             Python Python has further two applications :- 1. web application eg:- Django                                                               2. desktop application eg:- tkinter Libraries for GUI Pre defined libraries are : Kivy python QT Wx python tkinter Steps for making GUI Application Import tkinter module create GUI application main window Add widget Enter main event loop                                                 LAMBDA FUNCTIONS Lambda arguments : expression example : x = lambda a : a+10       ...

training day 5

                                  Functions in Python Functions in python consists of two parts : Calling and definition. Here def keyword is used to define the function .  Example : def one( ):                                                 #definition    print("Hello") one( )                                                         #calling Example : def one(last):   print(last + "Kaur") one("Jaspreet") one("Parneet") Parameter with default value : Example :   def one(first = ''Jaspreet'')      print(first + "kaur") one("Puneet") one() Parameter p...

training day4

                                              SETS  fruits = {"apple","banana","cherries"}  for x in fruits:       print(x) To check whether the item is there or not in the set use :                                   print("banana" in fruits)    It will tell only true or false but not index because it is unindexed. To add any single item                                  fruits.add("orange") If  we want to add multiple items                                 fruits.update(["mango","orange"]) If there is no item in the set, we want to remove it will give error ...

training Day3

                                               Tuples Program to find largest number in list list = [1,4,8,9,7,4] x=1 for n in list:     if x > n :        x = n print(x) Program to guess a number  guess_count = 1 guess_limit =3 number = 9 while guess_count <= guess_limit :       guess = int(input("Enter the number"))       if(guess == number) :           print("You win")           break      guess_count += 1     else :        print("You failed") Program for Car game command = " " started = False while True :    command = input("Enter command").lower()    if command == "start":         if started :   ...