-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathevilOptimized.py
More file actions
34 lines (28 loc) · 964 Bytes
/
evilOptimized.py
File metadata and controls
34 lines (28 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def checkEvil(number):
'''
Objective : To check whether given number is evil or not.
Input Variables :
:param number: Given number to check if evil or not.
Return Value : Bool Value - True or False, if Evil the True else False
'''
#Approach : Count the number of 1's in it's binary form using traditional
# method of finding binary equivalent.
count = 0
while (number != 0):
if number % 2 == 1:
count += 1
number = number // 2
if count % 2 == 0:
return True
else:
return False
def main():
number = int(input('Enter a number: '))
isEvil = checkEvil(number)
print(number, 'in Binary is', bin(number))
if isEvil == True:
print(number, 'is Evil Number.')
else:
print(number, 'is not Evil Number.')
if __name__ == '__main__':
main()