-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenge04.py
More file actions
36 lines (32 loc) · 1012 Bytes
/
Copy pathchallenge04.py
File metadata and controls
36 lines (32 loc) · 1012 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
35
# Euler Challenge number 4
# Find the largest palindrome product of two 3 digit numbers
# This function is used to retrieve all products of two 3 digit numbers
# using embedded while loops
def getProducts():
firstnum = 999
secondnum = 999
mypal = 0
while firstnum > 0:
while secondnum > 0:
product = secondnum * firstnum
answer = isPalindrome(product)
if answer == "true":
if mypal < product:
mypal = product
secondnum = secondnum-1
firstnum = firstnum-1
secondnum = 999
return mypal
# Check to see if the product is a palindrome
# Called from getProducts
def isPalindrome(mynumber):
myreturn = "false"
test = str(mynumber)
if test == ''.join(reversed(test)):
myreturn = "true"
print(mynumber)
return myreturn
# These are the function calls to kick of the program
mypal = getProducts()
print("And the largest palindrome found is ...")
print(mypal)