Checking Number is Even Or Odd Is very Easy Task .
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 .
Second Problem is , Taking integer data of order 10^10000
Third Problem is , How to check in optimize time
Output :-
- num=int(raw_input())
- if num%2==0:
- print 'Even'
- else:
- 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 :
- hile True: #infinite LOOP
- inp=raw_input() # Taking Input As String
- if inp=='-1': #Condition To break Out From LOOP
- break
- if inp[-1] in '02468': #cheking Last digit of input to check Even or ODD
- print 'EVEN'
- else:
- print 'ODD'
Output :-
Fantastic items from you, man. I've remember your stuff previous to and you are just extremely magnificent.
ReplyDeleteI 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)
Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your weblog?
ReplyDeleteMy 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 ()
Yeah This is This is Alright with me , !!
Delete