Welcome again to everybody! Make yourself@home. In the time-honoured tradition of our group, here is the weekly discussion thread.
● Matrix homeserver and space
● Theory discussion group on Matrix
● Find theory on ProleWiki, marxists.org, Anna’s Archive and libgen; audio versions by Socialism For All
I figured it out! I just needed to use break.
num = [] Ms = [] def Fmmin(va): while va == 0: for n in range(2, number): if number % n == 0: va = n break if n == number - 1 and number - 1 % n != 0: va = '0' return va def Fmmax(va): while va == 0: for n in range(number-1, 1, -1): if number % n == 0: va = n break if n == 2 and number % n != 0: va = '0' return va for f in range(1,10000000): number = 452021 + f mmin = 0 mmax = 0 mmin = Fmmin(mmin) mmax = Fmmax(mmax) if int(mmax) > 0 and int(mmin) > 0: M = mmax + mmin if M % 7 == 3: num.append(number) Ms.append(M) if len(num) >= 5: break print(Ms) print(num)
You can improve the code by returning
n
and0
respectively, no need to use a loop variable. Thewhile va == 0
is either unnecessary (if it runs once) or can cause an endless loop (since nothing changes between iterations)Fixed it now!
def Fmmin(): for n in range(2, number): if number % n == 0: return n if n == number - 1 and number - 1 % n != 0: return 0 def Fmmax(): for n in range(number-1, 1, -1): if number % n == 0: return n if n == 2 and number % n != 0: return 0
one more piece of advice: try to avoid global variables when possible (in this case, you could pass
number
as an argument instead)