Last active
January 6, 2016 22:19
-
-
Save ozgurkaracam/22c699b8b0958f71ec12 to your computer and use it in GitHub Desktop.
2014 Final Soru 4 196 problemi
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
#SORU-4: 196 Problemi | |
#Kullanıcıdan alınan en az iki basamaklı sayı (örneğin abc) alıp, bu sayının ters yazılmışını (cba) hesaplayan. | |
#Ve bu sayıların toplamı palindrom (düz ve ters yazılışı aynı olan. Örneğin 12321) olmasına kadar hesaba | |
#devam eden programı yazınız. Bu kuralla hesaplanabilen en küçük sayı 196 olduğundan bu probleme 196 problemi | |
#denilir. Örnek, | |
#Girdi: 57 | |
#Ara hesaplar | |
# 57 + 75 = 132 | |
#132 + 231 = 363 (palindrom, programı sonlandır) | |
def hesapla(sayi): | |
terssayi=str(sayi)[::-1] | |
terssayi=int(terssayi) | |
if polindrom(str(terssayi+sayi)): | |
print (str(sayi)+"+"+str(terssayi)+"="+str(sayi+terssayi)+" bir polindrom.") | |
else: | |
print (str(sayi)+"+"+str(terssayi)+"="+str(sayi+terssayi)) | |
return hesapla(terssayi+sayi) | |
def polindrom(sayi): | |
sayi=list(sayi) | |
if len(sayi)<2: | |
return True | |
elif sayi.pop(0)!=sayi.pop(): | |
return False | |
else: | |
return polindrom(sayi) | |
print (hesapla(57)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment