-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex_4.py
executable file
·36 lines (29 loc) · 930 Bytes
/
ex_4.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
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 12 10:22:17 2021
@author: Daneshjoei
"""
"""example4:
find the largest palindrome number which is a product
of two 3-digit numbers.
"""
# a number which is a product of two 3-digit numbers
# is either 5-digited or 6-digited
# in order to find the largest we start from searching
# through the 6-digit numbers and if we do not find any
# we search among the 5-digit numbers.
#the function tests whether a number is palidrome or not
def IsPalindrome(Num):
MyStr=str(Num)
for i in range(0,len(MyStr)//2):
if MyStr[i]!=MyStr[len(MyStr)-1-i]:
return False
return True
Compare=0
for i in range(999,99,-1):
for j in range(999,99,-1):
if IsPalindrome(i*j):
Max=max(i*j,Compare)
Compare=Max
break#the break is because we want the max
print(Max)