Tuesday, 16 April 2019

jahab

IoT:
-----
The Internet of things is the extension of Internet connectivity into physical devices and everyday objects. Embedded with electronics, Internet connectivity, and other forms of hardware, these devices can communicate and interact with othe
rs over the Internet, and they can be remotely monitored and controlled.

Saturday, 13 April 2019

#Program 1: print n times(increment)
n=int(input("Enter the value of n : "))
for i in range(1,n,1):   #i=1,i<n,i++
    print(i,"  jahab")

#Program 2: print n times(increment)
n=int(input("Enter the value of n : "))
for i in range(1,n+1,1):   #i=1,i<=n,i++
    print(i,"  jahab")

#Program 3: print n times(decrement)
n=int(input("Enter the value of n : "))
for i in range(n,0,-1):   #i=n,i>0,i--
    print(i,"  jahab")

#Program 4 : Display even number in given input
n=int(input("Enter the value of n : "))
for i in range(2,n+1,2):
    print(i)

#Program 5 : Display even number in given input
n=int(input("Enter the value of n : "))
for i in range(1,n+1,1):
    if (i%2==0):
        print(i)

#Program 6 : Display even number & sum of even in given input
n=int(input("Enter the value of n : "))
s=0
for i in range(1,n+1,1):
    if (i%2==0):
        s=s+i
        print(i)
       
print("sum of even number is :",s)

#Program 7 : sum of digits
n=int(input("Enter the value of n : "))
s=0
for i in range(1,n+1,1):
        s=s+i
        print(i)
print("sum of Digits :",s)

#Program 8 : find factorial value
n=int(input("Enter the value of n : "))
s=1
for i in range(1,n+1,1):
        s=s*i
        print(i)
print("Factorial is :",s)


#Program 9 : display n times using while loop(increment)
n=int(input("enter the value of n : "))
i=1
while(i<=n):
    print(i," jahab")
    i=i+1

#Program 10 : display n times using while loop(decrement)
n=int(input("enter the value of n : "))
i=n
while(i>=1):
    print(i," jahab")
    i=i-1

#Program 11: Reversed number
n=int(input("enter the value of n : "))   #123
c=0
while(n>0):   #123>0 ,12>0, 1>0,0>0
    a=n%10   #3,2,1
    n=int(n/10)   #12,1,0
    c=c*10+a  #3,32,321
print("Reverse number is :",c)


#Program 12: sum of integer(123 : 1+2+3 = 6)
n=int(input("enter the value of n : "))   #123
c=0
while(n>0):   #123>0 ,12>0, 1>0,0>0
    a=n%10   #3,2,1
    n=int(n/10)   #12,1,0
    c=c+a 
print("sum of integer is :",c)


#Program 13: Armstrong number(153 = 1(3)+5(3)+3(3) =153)
n=int(input("enter the value of n : "))   #123
n1=n
c=0
while(n>0): 
    a=n%10
    n=int(n/10) 
    c=c+a*a*a
print("Input :",n1,"\t Output :",c)
if c==n1:
    print("Armstrong Number")
else:
    print("Not Armstrong Number")
   
#note: 153,370,371,407
1. Perfect Number or not
2. Middle number is equal to sum of first and last number
3. Adam number or not Adam
------------------------------------------------------------------------------
#Program 1 : using nested for loop using increment
n=int(input("Enter the value of  n : "))
for i in range(1,n+1):
    for j in range(1,i+1):
        #print(i,end="")
        print(j,end="")
    print()

#Program 2 : using nested for loop using decrement
n=int(input("Enter the value of  n : "))
for i in range(n,0,-1):
    for j in range(1,i+1):
        #print(i,end="")
        print(j,end="")
    print()

#Program 3 : using nested for loop using decrement
n=int(input("Enter the value of  n : "))
for i in range(1,n+1):
    for j in range(n,i-1,-1):
        print(i,end="")
        #print(j,end="")
    print()
==========================================================

Python Looping:
-------------------
-Set of statement is repeated until condition is false

There are Two Types looping statements in Python
1. for loop
2. while loop                -  not support do while

1).for loop
-----------
 - Executes a sequence of statements multiple times and abbreviates the code that manages
   the loop variable.
Syntax:
-------
 for <variable> in <sequence>: 
      Statements #Body
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2). while loop:
---------------
-Repeats a statement or group of statements while a given condition is TRUE.
Syntax:
-------
    while <expression>: 
     Statements #Body 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Nested Loops: (patter design ,table format)
-------------
i.  Nested for loop
ii. Nested while loop

1. Nested for loop
-------------------
-for Loops defined within another Loop is called Nested for Loop.
-When an outer for loop contains an inner for loop in its body it is called Nested for Looping.

Syntax:
-------
    for  <expression>: 
      for <expression>: 
          Body  #inner loop Statements 
      Body       #Outer loop Statements
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

2. Nested While Loop
--------------------
-while Loops defined within another Loop is called Nested while Loop.
Syntax:
-------
    while  <expression>: 
        while <expression>: 
            Body  #inner loop Statements 
        Body       #Outer loop Statements
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Loop Control Statements
~~~~~~~~~~~~~~~~~~~~~~~~
1. break
2. continue
3. pass

1. break statement
   ---------------
-Terminates the loop statement and transfers execution to the statement
 immediately following these loop.
Syntax:
------
   while <expression>: 
       Statements #Body
       if (cond) : 
          break
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2. continue statement:
----------------------
-Causes the loop to skip the remainder of its body and immediately
 retest its condition prior to reiterating.
Syntax:
-------
     while <expression>: 
       Statements #Body
       if (cond) : 
          continue
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3. Pass statement
----------------
 - In Python, pass keyword is used to execute nothing; it means, when we don't want to execute code,
   the pass can be used to execute empty. It is same as the name refers to.
   It just makes the control to pass by without executing any code.
   If we want to bypass any code pass statement can be used.
Syntax:
------
for <variable> in <sequence>: 
      Statements #Body
      if (cond) : 
          pass
Ex:
for i in range(1,5):
    if i==3:
        pass
 print "This is pass block"
    print i
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#Program 1: +ve or –ve Using simple if
n=int(input("Enter input :"))
if n>0 :
    print ("+ve number")
---------------------------------------------------
#Program 2: +ve or –ve Using simple if else
n=int(input("Enter input :"))
if n>0 :
    print ("+ve number")
else :
    print ("-ve number")
---------------------------------------------------
#Program 3: Even or Odd number using simple if else
n=int(input("Enter input :"))
if (n%2)==0 :
    print ("even number")
else :
    print ("odd number")
---------------------------------------------------------
#Program 4: Biggest in 2 numbers using simple if else
a=int(input("Enter First input :"))
b=int(input("Enter Second input :"))
if a>b :
    print ("a is biggest")
else :
    print ("b is biggest")
--------------------------------------------------
#Program 5: Biggest in Three Numbers using else if ladder
a=int(input("Enter First input :"))
b=int(input("Enter Second input :"))
c=int(input("Enter Third input :"))
if a>b and a>c:
    print ("a is biggest")
elif  b>c :
    print ("b is biggest")
else:
    print ("c is biggest")
--------------------------------------------------
#Program 6: Using else If ladder
n=int(input("Enter input :"))
if n>0 :
    print ("+ve number")
elif n==0 :
    print ("Given input is zero")
else :
    print ("-ve number")
------------------------------------------------
#Program 7: Using Nested If
roll=int(input("Enter Roll : "))
name=input("Enter Name : ")
m1=int(input("Enter Mark1 : "))
m2=int(input("Enter Mark2 : "))
m3=int(input("Enter Mark3 : "))
tot=m1+m2+m3
avg=tot/3

if(m1>=35 and m2>=35 and m3>=35):
    result="pass"
    if(avg>=90):
        grade="A++"
    elif(avg>=80):
        grade="A+"
    elif(avg>=70):
        grade="A"
    elif(avg>=60):
        grade="B"
    elif(avg>=50):
        grade="c"
    else:
        grade="Nil"
else:
    result="Fail"
    grade="Nill"

print("Roll \t Name \t Total \t Average \t Result \t Grade")
print("-----------------------------------------------------")
print(roll,"\t",name,"\t",tot,"\t",avg,"\t",result,"\t",grade)
-----------------------------------------------------------------------------------------
#Program 8: Using Nested If
a=int(input("Enter First input :"))
b=int(input("Enter Second input :"))
c=int(input("Enter Third input :"))
if a>b:
    if a>c:
        print ("a is biggest")
    else:
        print ("c is biggest")
else:
    if b>c :
        print ("b is biggest")
    else:
        print ("c is biggest")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Python Control Structures
-----------------------
-change the order of execution
-flow the control of execution(ignore or skip, repeate)
1. Conditional statements (if)  - not support switch
2. unconditional statements (break,continue,pass) not support goto
3. looping statements : iteration or repeative statement (for,while)   not support do while

1. Python conditional statements:
----------------------------
-control can be transfer into one place to another place with using condition

Python If Statements
-------------------
-check the given input is correct(true) or not(false)

There are various types of if statements in Python.

1. if statement
2. if-else statement
3. nested if statement
4. elseif statements

1. if statements
---------------
  -true part only
Syntax:
-------
  if(condition): 
     statements
-----------------------------   
2. if...else statements
-----------------------
-true and false
-only one condition
Syntax:
------
  if(condition): 
    statements
  else:
    statements
----------------------------
working:
----------
 -First test condition is evaluated
 -if the given condition is true than execute the true part statements
 -otherwise execute the else part statement

3. else if statements
---------------------
-more than one condition
Syntax:
------
  if(condition): 
     statements
  elif(cond):
     statements
  elif(cond):
     statements
  ....
  ....
  else: 
     statements
   
4. Nested if statements
------------------------
Syntax:
-------
  if (condition):
     if (condition):
         statements
     else: 
         statements
=======================================
#Example 1: Basic Program for basic data types(int,float,string,complex)
a=10
b=3.14
c="jahab"
d=3+2j
e=None
print(a)
print("a =",a)
print("b =",b)
print("Floating value is : %0.1f"%b)
print("c =",c)
print("d :",d)
print("a : ",a," b :",b)
print("a={},b={}".format(a,b))
---------------------------------------------------------
#Example 2:
a1 = 5
print(a1, "is of type", type(a1))
print(a1, "is Integer number?", isinstance(a1,int))
print(a1, "is Float number?", isinstance(a1,float))

a2 = 2.0
print(a2, "is of type", type(a2))
print(a2, "is floating number?", isinstance(a2,float))

a3 = 1+2j
print(a3, "is of type", type(a3))
print(a3, "is complex number?", isinstance(a3,complex))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Note:
------
* type() - type() function to know which class a variable or a value
* isinstance()- isinstance() function to check if an object belongs to a particular class.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Program 1: Add Two Numbers
a=10
b=20
c=a+b
print ("Addition result is : ",c)
print ('Addition result is : ',c)
print ('Addition result is : '+str(c))

#Program 2: Add Two Numbers using input function
a=input("Enter First value :")
b=input("Enter Second value :")
c=int(a)+int(b)
print ("Addition result is : ",c)

#Program 3: Add Two Numbers using input function
a=int(input("Enter First value :"))
b=int(input("Enter Second value :"))
c=a+b
print ("Addition result is : ",c)

#Program 4: Arithmetic Calculations
a=int(input("Enter First Value :"))
b=int(input("Enter Second Value :"))
add=a+b
sub=a-b
mul=a*b
div=a/b
rem=a%b
print ("Addition result is : ",add)
print ("subtraction result is : ",sub)
print ("Multiplication result is : ",mul)
print ("Divide result is : ",div)
print ("Divide result is : %0.2f"%div)
print ("Remainder result is : ",rem)

#Program 5: Simple Interest Calculation
p=float(input("Enter P:"))
n=float(input("Enter N:"))
r=float(input("Enter R:"))
si=p*n*r/100
print ("Simple ins :",si)


#Program 6:  Volume of Cone
r=float(input("Enter r :"))
h=float(input("Enter h :"))
v=(1.0/3.0)*3.14*r*r*h
print ("Cone :%0.2f" %v)

#Program 7:  Volume of Sphere
r=float(input("Enter r :"))
v=(4.0/3.0)*3.14*r*r*r
print ("Sphere :",v)

#Program 8:  Using math function
import math
n=int(input("Enter input :"))
dis=math.sqrt(n)
dis1=math.pow(n,2)
print (dis)
print ('Power ',dis1)
print ('Pi ',math.pi)

#Program 9:  Using math function(cone)
import math
r=float(input("Enter r :"))    #convert string to floating value
h=float(input("Enter h :"))
v=(1.0/3.0)*math.pi*math.pow(r,2)*h
print ("Cone :",v)

#Program 10: swapping two numbers using third variable
a=10
b=20
print("Before swapping")
print("a :",a,"\t b :",b)
t=a
a=b
b=t
print("After swapping")
print("a :",a,"\t b :",b)

#Program 11: swapping two numbers without third variable
a=10
b=20
print("Before swapping")
print("a :",a,"\t b :",b)
a=a+b
b=a-b
a=a-b
print("After swapping")
print("a :",a,"\t b :",b)
===============================================
2) Python Versions
    -------------------
Python 1.0 - 1994
 ...
Python 2.7 - 2010  (Python 2.x)
 ...
Python 2.7.15- May 2018
Python 2.7.16- March 2019

Python 3.7.0 - Jun 2018(Python 3.x)
Python 3.7.3 - Mar 2019
1) Python Basics
     ---------------
*Designed by : Guido van Rossum, Netherland
* Developer  : Python Software Foundation
* First appeared : 1990
* OS          : Cross-platform
* License : Python Software Foundation License & GPL(General Public License)
* Type       : OSS(Open Source Software) - Free download and use
* Filename extensions: .py, .pyc, .pyd, .pyo (prior to 3.5),.pyw, .pyz (since 3.5)
* Website : www.python.org
* Paradigm : multi-paradigm: (object-oriented, functional,procedural)
* Derived From : ABC, Modula-3,C,C++,Algol-68,Small Talk & Unix shell
Python application:
----------------------
1. Console Application(normal programs)
2. Window application(Desktop) - single window
3. webapplication(anywhere anyplace via internet)
4. Scientific application & Maths application
5. Data Analytics & Analysis(compare)
6. 3D Games
7. Database application(Python+Oracle,MsAccess,SQLite,MySQL)
8. Graphics & Animation(tortal (child))
9. GUI Application(Forms)
10. Chart(Pie,Bar)
11. Medical
12. Data Structure(store and receive data)
Python Features:
-------------------
--its support OOPS and general purpose language
--case sensitive language
--Cross Platform(support all OS(windows,UNIX,Linux,Mac)
--OSS(Open source Software) - free download and use
--Portable language(convert one OS to another OS)
--Its consist of Many Predefined functions(Library) and class
--Python allow User Defined function(user can create a own function)
--Type infer language(no need datatype) - auto predict
--Dynamic type system and automatic memory management
void main() Vs. int main(): main is a function with a special characteristic that the program execution always start from main. So the function main needs arguments and a return type. These int and void are its return type. Void means it will not return any value, which is also okay.
The short answer, is because the C++ standard requires main() to return int . As you probably know, the return value from the main() function is used by the runtime library as the exit code for the process. Both Unix and Win32 support the concept of a (small) integer returned from a process after it has finished.