首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用Python编写代码的Euler 4奇怪问题

用Python编写代码的Euler 4奇怪问题
EN

Stack Overflow用户
提问于 2013-06-25 23:24:41
回答 1查看 78关注 0票数 0

第一个问题:为什么这个警告会出现在“非ascii”上?问我可以这样做:-编码: cp1252 --第二个问题:代码下面的KeyError消息。

非常非常感谢大家。我重视你的回答和建议。

代码语言:javascript
复制
    ##Largest palindrome product Problem 4
##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.

    def is_palindrome(number):
return str(number) == str(number) [ : : -1]
    if __name__ == "__main__":
print ( " { } and {  } => {  } ".format(*max( (i, j, i*j )
                    for i in range(1000, 900, -1)
                        for j in range(1000, 900, -1)
                            if is_palindrome (i*j))))
##Traceback (most recent call last):
##  File "C:/Python27/Euler prob 4.py", line 11, in <module>
##    for i in range(1000, 900, -1)
##KeyError: ' '
EN

回答 1

Stack Overflow用户

发布于 2013-06-25 23:31:58

如果您将某些内容放入{}格式中,将尝试将其用作键--即使它是一个空格。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17309177

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档