#WSQ11

Yo soy 196

Your jobs is to create a program that asks the user for two pieces of data:

  • The lower bound of the sequence
  • The upper bound of the sequence
Then you check the values from the lower bound (inclusive) to the upper bound (inclusive) and make a report of them. During the analysis of each number, if a Lychrel number is found it should be reported immediately with something like “Found a Lychrel number: 196″
 
def palindromes(x):
    x1 = str(x)
    x2 = x1[::-1]
    x3 = int(x2)
    if(x==x3):
        return True
    else:
        return False
nonlycherels = 0
Lycherels = 0
npalindromes = 0
x = int(input(“Give me the lower bound: “))
y = int(input(“Give me the upper bound: “))
print(“Range of numbers analysed: From”,x, “to”,y)
for c in range(x,y+1):
    c1 = palindromes(c)
    if(c1==False):
        c2 = 0
        p1 = False
        candidate = c
        while(c2<30 and p1==False):
            c2 = c2 + 1
            c3 = str(candidate)
            r = c3[::-1]
            r1 = int(r)
            candidate = candidate + r1
            p1 = palindromes(candidate)
        if(p1==True):
            nonlycherels = nonlycherels + 1
        if(c2==30 and p1==False):
            Lycherels = Lycherels + 1
    else:
        npalindromes = npalindromes + 1
print(“The number of natural palindromes is: “, npalindromes)
print(“The number of non-Lycherels is: “, nonlycherels)
print(“The number of Lycherel  is: “, Lycherels)
 

CC BY 4.0 #WSQ11 by Luis Vargas is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.