Posts

Python Class and Objects

Image
Python Class and Objects What is class and object ? class :- it is a structure which is used to where you put your data and any function that you want  for example : if you buy any house it is full empty in that room you see a kitchen, bedroom, hall this we example of class and when you put something in the house like T.V, A.C, Sofa more.. it means you put some value on the class . in above left image is a class with no value and in right their is a class with value  for understanding replace class with hall and value with (TV, Sofa etc..) How we can implement class and object in python ? To create a class, use the keyword  class : Example : class   Room :         total_sofa =  5 this way we create class in python. How we can access class variable (ex: total_sofa ) value ? Answer: by using "object" let me explain don't get confuse  To create a object, we use : syntax : object = class_name() Create an object named p1, and print the value of total_sofa: Example : p1 = Room

Fibonacci series in python

Image
Fibonacci Series Fibonacci series is 0,1,1,2,3,5,8,13,21,34,............,infinity . It is a sequence of number which follow some type of algorithm the alogrithm is  let  i = index position  a = it is a array of number  so to find a[i+1] = a[i]+a[i-1]. Note : fibonacci series always start with 0 and 1 and goes upto infinity.you can't start with your own values. Explanation: 1. 0 and 1 in starting is default values  2. if we go further the algorithm start adding previous 2 value and the answer is the next value.     as you can see the previous two value is 0 and 1 after adding both we get 1 as our 3rd value.     after that adding 1 and 1 we get our 4th value as 2 this entire cycle goes like this only. i think you get better understanding about fibonacci series we move further on coding of fibo  in python: Flowchart: coding: without recursion function: def fibonacci(n):      a = 0      b = 1      if n < = 0 :          print ( "Incorrect input" )      else :