我学习Python已经15天了,下面代码的每一步都需要您的指导。 此代码检查由两个3位数字的乘积生成的最大回文
非常抱歉,我提出了一个最愚蠢的问题
largest_palindrome = 0
for x in range(999,100,-1):
for y in range(x,100,-1):
product = x*y
check = str(x*y)
if check == check[::-1]:
if product > largest_palindrome:
largest_palindrome = product
print(largest_palindrome) ```
- Need clarification on the below:
for x in range(999,100,-1): #why is -1 introduced here. what is the range it is checking in (999,100,-1)
for y in range(x,100,-1): # why is x introduced in y loop. how much times it will check the range.
product = x*y
check = str(x*y)# why is string introduced here ?
if check == check[::-1]: # what does this line mean?
if product > largest_palindrome:
largest_palindrome = product
print(largest_palindrome)
对于范围内的x(999100,-1):#为什么这里引入了-1。它正在签入的范围是多少(999100,-1)
对于范围(x,100,-1)内的y:#为什么在y循环中引入x。它将检查范围的多少次
check=str(x*y)#为什么这里引入字符串
如果check==check[:-1]:#这行是什么意思
相关问题 更多 >
编程相关推荐