Saturday, 16 March 2019

states and transition class 11 python cbse.

STATES AND TRANSITION

STATE: A state is a state of computation with a specific set of information that is sufficient to determine the future possible behavior.

TRANSITION:A marked change from one state to another in response to some external input and or stimulus.

STATES AND TRANSITION DIAGRAM

It is used to represent roots from one state to another in these diagram.

The circles represent state.

Arrow represent transition.
EX.


Sorting class 11 python cbse

SORTING

It refers to arranging element in a specific order ascending or descending 

BUBBLE SORTING

The basic idea is to compare 2 adjoining values and exchange ,then if they are not in proper order.In every pass the heaviest element settles at its appropriate position in the bottom.

BUBBLE SORT

alist=[15,6,13,22,35,2]
print("original list is'' : alist)
        n=len(alist)
for i in range (n):
     for j in range (0,n-j,-1):
           if alist (i)>alist (j+1):
                     alist=(j+1):
print("list after sorting:,alist)

INSERTION SORT

lst=[15,14,2,3,4,5,6,77,88,90]
print("original list is:"lst)
for i in range (1,len(lst)):
          temp=lst[i]
          j=i-1
          while j>0 and temp<lst[j]:
                  lst[j+1]=lst[j]
                   j=j-1
             else:
                  lst[j+1]=temp
print("list after sort is:",lst)

Debugging class 11 python cbse

DEBUGGING

Finding error, reasons of their occurrence and technique of their fixation. 

Error and Exception

  • Errors and exceptions, both interrupts the program execution.
  • Errors and exception are not same.
  1. Error, usually finds out at the time of translation.
  2. whereas, exception generates during program run, due to an input.
  • An error is also known as bug,is a programming code that prevents a program from its successful interpretation.

Error are of three type:

  1. Compile time error 
  2. Run time error 
  3. Logical error
  • Compile time error 
These error are basically of two types.
  • Syntax error: Violation of formal rules of a programming language results in syntax error.
for ex:
   x=(x*y)
  • semantics error: semantics refer to the set of rules which sets the meaning of statements.Meaning less.
x*y=z

  • Logical error
If a program is not showing any compile time error or run time error but not producing deride output, it may be possible that program is having a logical error. This error generates because of wrong analysis by programmer.
For ex. To use a variable without an initial value.

  • Run time error
These errors generates during a program execution and known as run time error.
some run time error are difficult to find out.
some error prevent a program from execution which is known as program crash or abnormal fermentation of program.

EXCEPTION

  • Exception is a state when a program turminance abnormally unit cant't be controlled.
ex. a=10 
      b=0
(=a/b(Mathematics exception)
An uncertain cause termination of a program.

Exception handling in python

  • Try and except claim are used to handle an exception.
Try 
# Code with probability of exception will be written here.

Except
# Code to handle exception will be written here.

Hoe to debug a program?

An error can debugged by correcting the code.
There are following techniques of debugging.
  • To identify the place of error generation.
  • By tracing the program code.

Detection origin of an error

When you run a code interrupt will run a line of code if it is free from any syntax and semantics error. And will visit the error if the running line of code has some error.

Printing of step wise value of variable

Depending upon your algorithm the variable value change during the execution some times we get incorrect output but cannot figure out what is causing it, in that case it is good idea to add many inspect values of variables after each step.

Tracing of code 

Code tracing means executing code one line at a time and watching it's impact on variable, it is often done with butin debugging tools also known as debugger.

Break Point

Break point are temporary halt maker in source code that stop the debugger at the marked code line by line from top to bottom and half at the where the break point is setup.

tuples class 11 python cbse

TUPLES


  • Tuples is also kind as container which can store list of any kind of values.
  • Tuples is a immutable data type which means we can not change any value of tuple.
  • Tuple is sequence like string and list but the different is that list is mutable whereas string and tuple are immutable.

CREATION OF TUPLES

  • Empty tuple: >>>t = ( ) 
  • Single tuple: >>>t = (1)
  • Nested tuple: >>>t = (1,12,2,(2,3))
  • Long tuple: >>>t = (1,2,3,4,5,6,7)

Tuple functions 

  • len( ) function
  • max( ) function
  • min ( ) function
  • index ( ) function
  • tuple( ) function

Unpacking Tuple

Forming a tuple from individual value is called packing and creating individual values from a tuple element is unpacking.

FOR EXAMPLE:

t = (1,2,'A','B')
length= 4
w,x,y,z= t
print(w)

         1


List creation class 11 cbse

LIST CREATION

  • List is sequence which can store value of and kind.

CREATION OF LIST

  • >>>Mylist = list('hello')
          >>>Mylist 
                 ['h','e','l','l,'o']
  • >>>L1= list(input("enter list element"))
          Enter list Element 1,2,3,4,5
          >>> L1
          (1,2,3,4,5)
eval( ) function identifier type of passed string and then return it.

>>>a="15"
>>>b="25"
>>>print(a+b)
       1525
>>>print(eval(a)+eval(b))
       40

Accessing of list

  • len( ) function is used to get the length of list.
  • L[i] will return the value exist at index.
  • L[i:j] will return a new list with the values from i index to j list excluding j index.

Transverse of list

Transverse of a list means to access and process each and every element of that list.

List slicing

  • To slice a list index is-
>>>lst = [10,12,14,20,22,24,30,32,34]
>>> SEQ= lst[3:-3]
>>>SEQ
      [20,22,24]

SEQ=list[start:stop]
seq=list[start:stop:step]

string manipulation class 11 cbse

STRING MANIPULATION

STRING CREATION
  • By assigning value direct to the variable
>>> str ="I love myself"
>>> str
I love myself
  • By taking input
>>> str= input("enter a number")
     Enter a string This is python
>>> str 
     This is python

Transverse of a string

string1= input("Enter a string:")
print("The",string1,"in reverse order is:")
length= len(string1)
for a in range (-1,(-length),-1))
      print(sting1[a])

Membership operator in a string.

  • in operator result into True or False.
like= "a" is in "pradeep"will result into true.
  • not in
"k" not in "kumar" will result false.

String comparison operators

upper case and lower case has different unicode value.
EX. "A"=="a" false
       "abc"=="ABC" false
       "b"=="b" true

How to get unicode/ Ordinal value

>>>ord('a')
   97
>>>ord('A')
   65
>>> char(97)
   A

fundamental of python class 11 cbse part 3

PART 3

FLOWCHART

Flowchart is a graphical representation of an algorithm, workflow or process. The flowchart shows the steps as boxes of various kinds, and their order by connecting the boxes with arrow.

Conditional (if) statement.

In python, if statement is used to select statement is to be done on the basis of a condition, if statement.
if <condition>:
                statement.

if-else statement.

if<condition>:
                   statement when condition is true.
else:
      statement when condition is false.

if-elif statement.

a=int(input("Enter a number"))

if a==10:

           print("a is equal to 10")

elif a==20:

           print("a is equal to 20" )

else:

           print("a is not equal to 10 and 20")

NESTED if-else.

a=int(input("enter a no.")) 
b=int(input("enter a no."))
c=int(input("enter a no."))
if a>b:
        if a>c:
                  print("a is greater")
    else:
           print("c is greater")

in and not operator.

  • in operator 
           3 in [1,2,3,4] will return true.
           5 in [1,2,3,4] will return false.
  • not operator
           5 not in [1,2,3,4] will return true.

While loop

n=int(input("enter a no."))
c=1
while c<11:
           print(n,"x",c,"=",c*n)

JUMP STATEMENT(break)

n=int(input("enter a number"))
  c=1 
while c<11:
         is c==5:
              break
           print

CONTINUE STATEMENT

n=int("input a no."))
c=0
while c<11:
c=c+1
if c==5:
       continue
print (n,"x",c,"=",c*n)