Saturday 1 February 2014

Program to Convert Binary Number to Decimal.

Hey Guys! Ever got frustrated doing manual calculations for converting BINARY NUMBERS to DECIMAL? If Yes! You may get relief from that now! Today i am gonna show you to write the program in Python which asks the user to enter the binary number and converts it to its decimal equivalent.

Before we get started we need to be very clear about how actually the binary number is converted to its decimal equivalent. So here it is:

  • Each number system has a base also called a Radix. A decimal number system is a system of base 10; binary is a system of base 2.What are these varying bases? The answer lies in what happens when we count up to the maximum number that the numbering system allows. In base 10, we can count from 0 to 9, that is,10 digits and in binary we count 0 and 1 i.e. two digits
  • Now method to convert Binary number to decimal:
    • Start at the rightmost bit.
    • Take that bit and multiply by 2^n where n is the current position beginning at 0 and increasing by 1 each time. This represents a power of two.
    • Sum each terms of product until all bits have been used.
  • Let us take an example:
    • Convert the Binary number 101011 to its Decimal equivalent
    • 1 * 2^5 + 0 * 2^4 + 1 * 2^3 + 0 * 2^2 + 1 * 2^1 + 1 * 2^0
    • 32 + 0 + 8 + 0 +2 + 1 = 43
So there we go, now we know how to convert binary to decimal. So let's have a look on the program.
Explanation source: Python Class XI CBSE book



This is the program which prompts the user to enter the binary number and converts it into Decimal number.
The program has been commented line by line for user's consent, Still if there is any query, the reader is free to express his/her views in the comments.

THE FOLLOWING IS THE OUTPUT OF THE PROGRAM:


Hope You Must have enjoyed the Post! Cheers! Enjoy! And Don't Forget to give your FeedBack!


Saturday 7 December 2013

Program to check the "PASSWORD" is Correct or Incorrect!

Hey Guys! Today i am gonna show you the program which checks whether the password you entered is correct or incorrect based on some conditions applied.
1.)The Password must be of atleast 8 characters
2.)The Password should not contain Special Chracters
3.)The Password should contain atleast of two digits.

NOTE: The program is commented Line-by-Line for users consent..If still there is any problem,you are free to ask in comments.

a.) The following is the function which checks all the condtions and returns the values to the main function accordingly.


b.) The following Screenshot is of the functions which checks "Length of the password","Presence of Special Characters in password" and "Digits in the Password" Respectively.


c.)The following is the screenshot of the MAIN() where the program gets executed and ends.



Hope that you might have liked the post!

Saturday 30 November 2013

How to do selection sorting in Python 3.3.2 (For Integer Values)

Hi Guys! Today i am here with the Program which will sort the given list in ascending order.
So here it is:

1. This is a UDF (User Defined Function) which sorts the list provided by the user in Ascending order.The program asks the amount of numbers from the user to sort and then prompts him to enter the values one by one.
"THE PROGRAM HAS BEEN COMMENTED ON THE REQUIRED STATEMENTS FOR THE CONTENTMENT OF THE READER."


NOTE: THIS SELECTION SORT IS ONLY MEANT FOR INTEGER VALUES NOT FOR ANY STRING TYPE. THIS MEANS THAT YOU CAN EVEN APPLY MATHEMATICAL CALCULATION ON YOUR VALUES.
"IN NEXT POST I WILL BE POSTING ABOUT HOW TO SORT STRINGS."

Hope You Must Have Enjoyed The Program!!



Wednesday 27 November 2013

How to make Clock in Python 3.3.2

Hello Guys!! Today i will show you how to make Clock in Python 3.3.2 using classes.
So let's Begin:

1.The following is the screenshot of Class Time which shows the Modules and Data Members used in the program.



2.The following is the screenshot of Method of Class Time which is commented Line by Line for easy Understanding! The second last line is made as a comment by me(because it is only valid in COMMAND PROMPT, which is used to clear the output screen.).It should only be removed as a comment if you are running the program in Command Promt(not IDLE).



3. Following ScreenShot is the Main Program where Class is imported and Used.


Hope You Enjoyed the program!! New Ideas from the Readers are welcomed!!

Friday 22 November 2013

TV Remote Program In Python 3.3.2

This program is based on the working of the TV remote and is made using Classes.
1. Following is the screen shot of the Class TV.



2.This is part of the same class.



3.This is the Main Program where TV class is imported and used in the program.



Thursday 21 November 2013

Bank Loan Interest Program in Python 3.3.2

This Program is Made in Python 3.3.2 using the Classes. Program is commented Line-by-Line for the user's contentment.This program is made by keeping in mind all the Circumstances which Borrower can face.New Ideas are welcomed by the Reader.

1.This is the first part of the class 'Loan'. The Program Consists of Three Methods(Member Functions) and Nine Data Members(which are used in several ways in program) .In the following Picture,you can see GetBorrower Method which returns the name of the Borrower.



2. This is part of the same class which consists of two Methods(GetMonthlyPayment and GetTotalAmount).
The GetMonthlyPayment calculates the Monthly Installments of the borrower and prompts him to Pay the amount. Another Method(GetTotalAmount) returns the total amount to the borrower(user) which he has paid to the bank.


3.This the main program where we are importing the class and using it.



Hope You Might have liked this post!