本题来自 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. day40:python操作mysql:pymysql模块&SQL注入攻击

    目录 part1:用python连接mysql 1.用python连接mysql的基本语法 2.用python 创建&删除表 3.用python操作事务处理 part2:sql注入攻击 1.s ...

  2. node_第三方包下载文件package.jon详解

    配置原因第三方包的体积过大,不方便团队成员之间共享项目源代码共享时剔除node_modules 快速创建 package.json(只能在英文的目录下成功运行) npm init -y npm i 一 ...

  3. 力扣Leetcode 1248. 统计「优美子数组」

    统计「优美子数组」 给你一个整数数组 nums 和一个整数 k. 如果某个 连续 子数组中恰好有 k 个奇数数字,我们就认为这个子数组是「优美子数组」. 请返回这个数组中「优美子数组」的数目. 示例 ...

  4. java里equals和hashCode之间什么关系

    如果要比较实际内存中的内容,那就要用equals方法,但是!!! 如果是你自己定义的一个类,比较自定义类用equals和==是一样的,都是比较句柄地址,因为自定义的类是继承于object,而objec ...

  5. 总结一篇shell调试技巧及常见的脚本错误

      #常见的调试命令工具 1.使用bash命令参数调试 #使用 [root@game ~]# sh [-xvn] test.sh #参数解释: -x:将执行的脚本内容输出出来,可以看到执行的过程 -n ...

  6. 0vscode基本插件

    Bracket Pair Colorizer auto-close-tag Auto Rename Tag Bracket Pair Colorizer Dracula ESLint  Code Sp ...

  7. xAxis&yAxis

    const option = { color: ['#546570', '#2f4554', '#61a0a8'], xAxis: { type: 'category', data: ['Mon', ...

  8. Salesforce LWC学习(二十四) Array.sort 浅谈

    本篇参考:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/sort sal ...

  9. vue computed实现原理

    在 Vue.prototype._init 方法中的 initState 中有一个对于computed 的判断,如果有则执行 initComputed 方法初始化 computed. function ...

  10. 读网文《将20M文件从30秒压缩到1秒,我是如何做到的?》做实验

    先在微信公众号上看到网文<将20M文件从30秒压缩到1秒,我是如何做到的?>,然后在网上搜索了一下,看到了原文:https://www.jianshu.com/p/2e46ccb125ef ...