Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Redundant Iterations
#3
(Mar-13-2019, 07:11 PM)ichabod801 Wrote: It's not clear, because you haven't shown us how you call Optm in the first place. But if you only want the else clause to execute if none of the if clauses do, then the middle if's all need to be elif's (short for else if).

OrgH = [73.35,111.37,92.70,70.73,67.71,77.84]
BtmGap = 32
MinRH = 12
Div = 7
tH = 400

sH = sum(OrgH)
q = Div - len(OrgH)

def Optm(S, H, GH, q):

    s = H + GH

    if S >= s:
        K = S - s
    if S < s and GH > MinRH / 12:
        K = Optm(S, H, GH - 1, q)
    if S < s and GH <= MinRH / 12:
        K = Optm(S + 1, H, GH, q)


    if S == 494:
        print(K)
        print(K/q)
        print(s)
        print(S-s)
        print(GH)

    if q < 0:
        print("Somethign wrong with the category!")
    if q == 0:
        return 0

    else:
        minGap = K / q

        if minGap < MinRH:
            return Optm(S + 1, H, GH, q)
        if minGap >= MinRH and S <= s:
            return Optm(5 + 2, H, GH, q)
        else:
            return minGap




L = Optm(tH, sH, BtmGap, q)
sorry, I missed one line.
Reply


Messages In This Thread
Redundant Iterations - by leoahum - Mar-13-2019, 06:29 PM
RE: Redundant Iterations - by ichabod801 - Mar-13-2019, 07:11 PM
RE: Redundant Iterations - by leoahum - Mar-13-2019, 07:15 PM
RE: Redundant Iterations - by ichabod801 - Mar-13-2019, 07:26 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020