Saltar al contenido

número palíndromo en el ejemplo de código de Python

Ejemplo 1: palíndromo de cadena en python

n = input("Enter the word and see if it is palindrome: ") #check palindrome
if n == n[::-1]:
    print("This word is palindrome")
else:
    print("This word is not palindrome")

Ejemplo 2: cómo imprimir palíndromo en 100 entre 250 en python

>>> def isPalindrome(s):
    ''' check if a number is a Palindrome '''
    s = str(s)
    return s == s[::-1]

>>> def generate_palindrome(minx,maxx):
    ''' return a list of Palindrome number in a given range '''
    tmpList = []
    for i in range(minx,maxx+1):
        if isPalindrome(i):
            tmpList.append(i)

    return tmpList

>>> generate_palindrome(1,120)

[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111]

Ejemplo 3: wap en python para verificar que un número sea palíndromo o no

#A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward.
#Ex: madam or racecar.
#CODE BY VENOM
a=input("Enter you string:n")
w=str(a)
if w==w[::-1]: # w[::-1] it will reverse the given string value.
	print("Given String is palindrome")
else:
	print("Given String is not palindrome")
#CODE BY VENOM
#CODE BY VENOM

Ejemplo 4: palíndromo de python

def palindrome(a):
    return a == a[::-1]

palindrome('radar') 		# True

Ejemplo 5: número palíndromo + pitón

number=int(input("Enter any number :"))
#store a copy of this number
temp=number
#calculate reverse of this number
reverse_num=0
while(number>0):
    #extract last digit of this number
    digit=number%10
    #append this digit in reveresed number
    reverse_num=reverse_num*10+digit
    #floor divide the number leave out the last digit from number
    number=number//10
#compare reverse to original number
if(temp==reverse_num):
    print("The number is palindrome!")
else:
    print("Not a palindrome!")

Ejemplo 6: pitón palíndromo

#A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward.
#Ex: madam or racecar.
def is_palindrome(w):
	if w==w[::-1]: # w[::-1] it will reverse the given string value.
		print("Given String is palindrome")
	else:
		print("Given String is not palindrome")

is_palindrome("racecar")
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *