今天的任务是做练习题,做完后,最大的感受是format函数也太好用了吧,函数解析
http://www.runoob.com/python/att-string-format.html。下面主要记录一下今天做的一道练习的解题思路:

解题方法1:

解题思路:
假设x1<=10000,
现在要求的是满足以下条件的x1:
条件1:(x1+100)=A=indexindex
条件2:(x1+268)=B=index2index
因为x1<=10000
所以x1+100<=10100<=10268=x1+268
此处使用小于等于10268,是想先找到满足条件1或者条件2的A或者B,即
squares=[x1+100,x1+268,x2+100,x3+268....],可能A和B都存在,也可能只存在其中一个
所以利用for循环遍历列表,当遍历到A时,验证是否存在相应的B(B=A+168),如果存在就返回x1=A-100.
注:
最后的for循环改成下面这个也行,当遍历到B时,验证是否存在相应的A(A=B-168),如果存在就返回x1=B-268

解题方法2:这个就比较直观了,就是速度慢一点。

网友评论