Friday, 12 September 2014

Even or Odd

Checking Number is Even Or Odd Is very Easy Task .

  1. num=int(raw_input())
  2. if num%2==0:
  3.     print 'Even'
  4. else:
  5.     print 'Odd'


But If Someone say I gave you lots of Numbers to check Until I satisfied that your Program is correct .
And number is in range 0 to 10^10000



Than what will you do .

First Problem is , We don't Know number of Input user want to give 
     
  •  We Need TO create A infinite LOOP , with a condition To break .



Second Problem is , Taking integer data of order 10^10000

  • We can't store data as int or float . Even if we can it is meaningless because checking Even or ODD using division is wastage of time . So store data as string

Third Problem is , How to check in optimize time

  • We know Property of  Even Numbers if Number ends with {0,2,4,6,8} then even else Odd . So Just check last character of each string .

Python Code to Check Even or ODD :


  1. hile True#infinite LOOP
  2.     inp=raw_input() # Taking Input As String
  3.     if inp=='-1'#Condition To break Out From LOOP
  4.         break
  5.     if inp[-1] in '02468'#cheking Last digit of input to check Even or ODD
  6.         print 'EVEN'
  7.     else:
  8.         print 'ODD'




Output :-
EVEN OR ODD

3 comments:

  1. Fantastic items from you, man. I've remember your stuff previous to and you are just extremely magnificent.
    I actually like what you've obtained here, certainly like
    what you're stating and the way in which you assert it. You are making it enjoyable and you still care for to keep
    it smart. I can't wait to learn far more
    from you. This is actually a tremendous web site.


    Also visit my web page success factors (en.wikipedia.org)

    ReplyDelete
  2. Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your weblog?
    My blog site is in the exact same niche as yours and my users would certainly benefit from some of the information you present here.
    Please let me know if this alright with you. Appreciate it!


    My web site book of ra online for free ()

    ReplyDelete

THANKS FOR UR GREAT COMMENT

Blogger Widgets