本题来自 Project Euler 第4题:https://projecteuler.net/problem=4

# Project Euler: Problem 4: Largest palindrome product
# A palindromic number reads the same both ways.
# The largest palindrome made from the product
# of two 2-digit numbers is 9009 = 91 × 99.
# Find the largest palindrome made from the product of two 3-digit numbers.
# Answer: 906609 lst = []
for i in range(100, 999):
for j in range(100, 999):
if str(i*j) == str(i*j)[::-1]:
lst.append(i*j)
print(max(lst))

所谓的“回文积”(Palindrome Product),指的是某个数字,正着念、倒着念都一样,而且这个数字是另外两个数字之乘积。比如:9009 = 91 × 99,9009就是个回文数,而且是91和99的乘积,暂且就称之为回文积。本题就是求解两个三位数之积中的最大回文数。

因为此前在 Python练习题 025:判断回文数 里已做过类似的题目,所以也算是轻车熟路了。思路也很简单:用两个 for 循环轮番找出所有“两个三位数之积中的所有回文数”,用 max() 找出最大的那个即可。而判断回文数,最简单的就是用 str() 把数字转化为字符,如果 str == str[::-1],就判断为是回文,因为 str[::-1] 的作用就是把 str 倒着写。

Python练习题 032:Project Euler 004:最大的回文积的更多相关文章

  1. 【Python】【demo实验32】【回文数的确认】

    原题: 我的代码: #!/usr/bin/python # encoding=utf-8 # -*- coding: UTF-8 -*- #判断一个数字是否为回文数 即 12345654321 x = ...

  2. Python练习题 029:Project Euler 001:3和5的倍数

    开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...

  3. Python练习题 046:Project Euler 019:每月1日是星期天

    本题来自 Project Euler 第19题:https://projecteuler.net/problem=19 ''' How many Sundays fell on the first o ...

  4. Python练习题 039:Project Euler 011:网格中4个数字的最大乘积

    本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest pro ...

  5. Python练习题 033:Project Euler 005:最小公倍数

    本题来自 Project Euler 第5题:https://projecteuler.net/problem=5 # Project Euler: Problem 5: Smallest multi ...

  6. Python练习题 049:Project Euler 022:姓名分值

    本题来自 Project Euler 第22题:https://projecteuler.net/problem=22 ''' Project Euler: Problem 22: Names sco ...

  7. Python练习题 048:Project Euler 021:10000以内所有亲和数之和

    本题来自 Project Euler 第21题:https://projecteuler.net/problem=21 ''' Project Euler: Problem 21: Amicable ...

  8. Python练习题 047:Project Euler 020:阶乘结果各数字之和

    本题来自 Project Euler 第20题:https://projecteuler.net/problem=20 ''' Project Euler: Problem 20: Factorial ...

  9. Python练习题 045:Project Euler 017:数字英文表达的字符数累加

    本题来自 Project Euler 第17题:https://projecteuler.net/problem=17 ''' Project Euler 17: Number letter coun ...

随机推荐

  1. activiti app 6.0 乱码

    登录activiti-admin 乱码,解决后如下: 在catalina.bat文件中设置 -Dfile.encoding=UTF-8 1,windows 修改catalina.bat tomcat7 ...

  2. 使用Arcgis时,在sde空间库常用的相关函数

    一.Oracle库中配置好sde空间库常见的场景 1.在sde库中创建表:community 创建表:community 字段:id(INTEGER), shape(ST_GEOMETRY) 2.往s ...

  3. RabbitMQ入门指南

    消息队列(Message Queue,以下简称MQ)常用于异步系统的数据传递.若不用MQ,我们只能[在应用层]使用轮询或接口回调等方式处理,这在效率或耦合度上是难以让人满意的.当然我们也可以在系统间保 ...

  4. JDK源码分析-ArrayList

    ArrayList 储存结构 private static final Object[] DEFAULTCAPACITY_EMPTY_ELEMENTDATA = {}; transient Objec ...

  5. oeasy教您玩转linux010108到底哪个which

    到底哪个which 回忆上次内容 我们上次讲了查找命令位置whereis 我想找到whereis的位置怎么办?

  6. markdown 语法总结(一)

    1.标题 代码 注:# 后面保持空格 # h1 ## h2 ### h3 #### h4 ##### h5 ###### h6 ####### h7 // 错误代码 ######## h8 // 错误 ...

  7. 如何使用Xdebug单步调试PHP游戏服务器

    参考文章:https://www.sourcetoad.com/resources/debugging-php-save-time-with-xdebugs-remote-autostart/ 配置参 ...

  8. Unity透明地形

    http://answers.unity3d.com/questions/1162779/unity-5-transparent-terrain-shader.html http://answers. ...

  9. Pycharm 激活插件与码

    Pycharm2020最新永久激活码插件(支持Windows),100%永久激活 用到pycharm工具发现没用多久时间又过期了,在网上有看到很多朋友都遇到同样的情况,于是找到了一批很不错的永久激活方 ...

  10. php cookie及session

    1.会话控制概括 1)http协议的缺陷 无状态,就是无记忆,不能让同一浏览器和服务器进行多次数据交换时,产生业务的连续性, 2)什么是会话控制 会话控制就是解决http无记忆缺陷的,能够==将数据持 ...