Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python 2 layers if condition

I try my best to explain what I need:

If len(x) > 5:
   sample = func_sample(5)
   If sample meet conditionA:
      Then use sample
   Else go to elif bellow
Elif len(x) > 4:
   sample = func_sample(4)
   if sample meet conditionA:
      Then use sample
   Else go the else bellow
Else:
   sample = func_sample(3)

I know in VBA there is option goto but not in Python, so I am a bit struggling here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Something like this? (assuming you actually also use the sample in the last case…)

def get_sample(L):
    if L > 5:
       sample = func_sample(5)
       if conditionA(sample):
           return sample
    if L > 4:
       sample = func_sample(4)
       if conditionA(sample):
           return sample
    return func_sample(3)

sample = get_sample(len(x))
use_sample(sample)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading