-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1b.py
42 lines (38 loc) · 1.05 KB
/
1b.py
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
35
36
37
38
39
40
41
42
'''
1.b
Develop a Python program to check whether a given number is palindrome or not and
also count the number of occurrences of each digit in the input number.
'''
def count_occurrences_of_digits(num):
dictionary = {0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0}
temp = num
while(temp > 0):
dig=temp % 10
dictionary[dig] = dictionary[dig] + 1
temp = temp//10
return dictionary
def is_palindrome(num):
temp=num
rev=0
while(num>0):
dig=num%10
rev=rev*10+dig
num=num//10
if(temp==rev):
return True
else:
return False
def function_main():
digits_in_decimal = 10
num=int(input("Enter number:"))
num_is_palindrome = is_palindrome(num)
if(num_is_palindrome):
print("It is a palindrome")
else:
print("It is NOT a palindrome")
retuned_dictionary = count_occurrences_of_digits(num)
for i in range(digits_in_decimal):
print(i,"Occured",retuned_dictionary[i],"times")
if __name__=='__main__':
print(__doc__)
function_main()