-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8.py
73 lines (56 loc) · 1.65 KB
/
8.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'''
8.
Write a python program to find the whether the given input is palindrome or not (for
both string and integer) using the concept of polymorphism and inheritance.
'''
import math
class number:
def __init__(self):
self.stored_value = 0
def check_palindrome(self):
pass
class palindrome(number):
def __init__(self, passed_number):
self.stored_value= passed_number
def check_palindrome(self):
num=self.stored_value
rev=0
while(num>0):
dig=num%10
rev=rev*10+dig
num=num//10
if(self.stored_value==rev):
print("It is palindrome")
else:
print("It is not palindrome")
class palindrome_string_input(number):
def __init__(self,passed_string):
self.stored_value = passed_string
def check_palindrome(self):
num=int(self.stored_value)
rev=0
while(num>0):
dig=num%10
rev=rev*10+dig
num=num//10
if(int(self.stored_value)==rev):
print("It is palindrome")
else:
print("It is not palindrome")
def function_main():
base_num = number()
test_num = palindrome(12121)
base_num = test_num
base_num.check_palindrome()
test_num1 = palindrome(12122)
base_num = test_num1
base_num.check_palindrome()
string_num = palindrome_string_input("12121")
base_num = string_num
base_num.check_palindrome()
string_num1 = palindrome_string_input("12131")
base_num = string_num1
base_num.check_palindrome()
if __name__=='__main__':
print(__doc__)
function_main()