Created
November 29, 2010 18:38
-
-
Save enriqueaf/720340 to your computer and use it in GitHub Desktop.
Conseguir un número capicúa através de la suma de inversos y que cumpla la primera propiedad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
def es_capicua(numero): | |
snumero=str(numero) | |
for i in range(int(len(snumero)/2)): | |
if snumero[i] != snumero[-i-1]: | |
return False | |
return True | |
def sum_inverso(numero): | |
#Cramos inverso | |
nnumero = '' | |
snumero = str(numero) | |
for i in range(len(snumero)): | |
nnumero += snumero[-i-1] | |
return int(nnumero)+int(numero) | |
numero = input('Dame un numero: ') | |
querido=False | |
while not(querido): | |
snumero=str(numero) | |
querido=True | |
for i in snumero: | |
if int(i)<5: continue | |
querido=False | |
if querido: | |
capi = sum_inverso(numero) | |
if es_capicua(numero): print 'Capicua: '+snumero | |
#print numero | |
#time.sleep(2) | |
numero = sum_inverso(numero) | |
print ' ---------------- '+str(capi) | |
# Conjetura del capicua |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment