Friday 29 December 2017

Implemention of Binary Tree using Python

Implemention of Binary Tree Using Python 

The Python code is according to python 2.7

In computer science, a binary tree is tree data structure in which each node has at most two childe,each one referred a left child and right child
Each node contain three parts :-
1)Address of node on his left size 2)Value stored by node 3)Address of node on his right size
The Tree Represention Is As :->

PYTHON CODES

Code For creating Binary Tree

This code is only for creating the tree .If u try to run this u don't get any output on terminal I Know gays....the code is bit large .but i try my best to mini. it.


Code For creating Binary Tree with Printing in diferrent form


I use Overloading in the printing the Triee in different form
  • In-Order
  • Pre-Order
  • Post-Order

Output:-

C:\Users\rushi\Desktop\mypyDec>python bt2.py No of node to add >6 Enter node value >70 >40 >80 >15 >50 >75 Print Tree in IN-ORDER :- 15 40 50 70 75 80 Print Tree in Pre-Order :- 70 15 40 50 75 80 Print Tree in Post-Order :- 15 40 50 75 80 70 C:\Users\rushi\Desktop\mypyDec>

Tuesday 26 December 2017

Decimal to Binary Conversation using python








Convert Decimal to binary using python 2.7

Steps to convert Decimalto binary

step 1:- divide given number by 2
step 2:-record remainder from step1 as the rightmost digits
step 3:-divide the quotient of previous by 2
step 4:-record remainder from step3 as the next rightmost digits
step 5:-repeat untill zero at quotient







I specially recommend to use second  second code  (arithmetic logic code)









PYTHON CODES

Code Using function define by 

python itself



Code Using arithmetic

Output of prog using define fun.

python NoConv.py Enter Number in decimal form > 3 3 in binary = 0b11 ********** Enter x to end program or y to convert >y Enter Number in decimal form > 4 4 in binary = 0b100 ********** Enter x to end program or y to convert >x













Output of prog using arithmetic

rushi\Desktop\>python NoConv.py Enter input > 33 33 in binary :- 1 0 0 0 0 1 PS C:\Users\rushi\Desktop\mypyDec>

Saturday 23 December 2017

Fibonacci Number using Python Code

Fibonacci Numbers Using Pythan 

Definition :-

In mathematics,theFibonacci Number are numbers in following integer sequence 3,5,8,13,21,34,55

Fn=Fn-1 +Fn-2

where seed Values F1=1 and F2=1
The first 11 Fibonacci numbers Fn for n=0,1,2,....,11 are
f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11
0 1 1 2 3 5 8 13 21 34 55 89



PYTHON CODES



When the series start with any two consecutive user define no's


When the series start with 1 and user define Terms

Roots of Quadratic Equations using Python code


Roots of Quadratic Equations using Python code

ax2+bx+c=0
where x represents an unknown, and ab, and c represent known numbers such that a is not equal to 0. If a = 0, then the equation is linear, not quadratic.

cmath :- 


This module is always available. It provides access to mathematical functions for complex numbers. The functions in this module accept integers, floating-point numbers or complex numbers as arguments.

Root's of Q Equation




-------------------------------------Python Code-----------------------------------

import cmath
print 'input'
a=input('side 1')
b=input('side 2')
c=input('side 3')
inroot=b**2-(4*a*c)
sol1=(-b- cmath.sqrt(inroot))/(2*a)
sol2=(-b+ cmath.sqrt(inroot))/(2*a)

Check Number is Prime Using Python

Number is Prime Or Not



First We want to Know Theory of  Prime Number

prime number (or a prime) is  natural number greater than 1 that has no positive divisors other than 1 and itself. A natural number greater than 1 that is not a prime number is called a composite Number For example, 5 is prime because 1 and 5 are its only positive integer factors

The first 100 prime numbers (all the prime numbers less than 100) are:
2357111317192329313741434753596167, 7173798389, 97

Python Code for check Number  is prime or Not .

---------------------------------------------------------------------------------------------------------------------------


----------------------------------------------------------------------------------------------------------------------

compare three numbers

Compare Three Numbers In Simple Way

 First  way  :-

Let assume three no's num1 , num2 , num3  which we want to compare.
So we want a technique which we can learn faster and we can remember easily  and simple  .


----------------------------------------------------------------------------------------------------------------

while 1:
print '---------------------------------------------
        num1=float(input("Enter 1 no to check >  "))
num2=float(input("Enter 2 no to check >  "))
num3=float(input("Enter 3 no to check >  "))
        if num1>num2 and num1>num3:
larger=num1
elif num2>num3:
larger=num2
else:
larger=num3
print ' larger one %f' %larger

-------------------------------------------------------------------------------------------------------

Second way  :-

Let assume three no's num1 , num2 , num3  which we want to compare.
This is mostly used by programmer .
------------------------------------------------------------------------------------------------------
        while 1:
        num1=float(input("Enter 1 no to check >  "))
num2=float(input("Enter 2 no to check >  "))
num3=float(input("Enter 3 no to check >  "))
if num1>=num2 and num1>=num3:
larger=num1
elif num2>=num1 and num2>=num3:
larger=num2
else:
larger=num3
print ' larger number is %f' %larger

IT's Good