Posts

Showing posts from June, 2019

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 :   ...

training Day2

                                  PYTHON LANGUAGE Python  is an interpreted, high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python's design philosophy emphasizes code readability with its notable use of significant whitespace. Its language constructs and object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects. Python is dynamically typed and garbage-collected. It supports multiple programming paradigms, including procedural, object-oriented, and functional programming. Python is often described as a "batteries included" language due to its comprehensive standard library. Program using while loop in python to find factorial of a number  i = int(input("Enter number for factorial")) ...

training Day1

                       Commands for MySQL Mysql is basically a set of commands which help us to store some data in our database.  Here are the commands for Mysql: create database database; - used to create database. show databases; - used to show all the databases present. use databasename; - used to currently use the database. After using this command only we can perform actions in it. create table tablename(column1 datatype1,column2 datatype2,........); - used to create table with its attributes. insert into tablename values(value1,value2,.....); - used to insert values in the table show tables; - used to check tables. It will work only after we use any database. drop database databasename; - used to delete / Remove database. desc tablename; - used to check table description. When we want to retrieve data from table we use :                    ...