嘿,伟大的Python人
警告:我不熟悉编码。好吧,既然你被警告了。。。在
我试图编写一个python文件,它可以找到我在代码中声明的变量的最大素数。在
以下是我的思考过程:Step 1:Find Factors of X
Step 2:Put factors of X in an array a
Step 3:Analyze last element of array a
Step 4:Check if last element of array a is Prime
Step 5: if last element of array a is prime print "found the largest prime" along with the number itself, else, analyze second to last element in array a, and so on until at a[1]
Step 6: if no prime numbers in array, print "no primes found"
在处理数组中的x=28及其因子时,问题出现在最后一条else语句中的某个地方:
[1,2,4,7,14]我的代码认为7不是质数。。。在
我的步骤如下:
^{pr2}$
几个问题:如何重新分配x、ia[]和n等变量,使代码更具可读性
在第二个循环中,在第一次迭代之后,当分析7时,为什么代码没有识别出它是质数?
非常感谢您的任何建设性反馈!!在