[Tutor] Help with if-elif-else structure

Robert Sjoblom robert.sjoblom at gmail.com
Thu Aug 25 11:05:56 CEST 2011


>> #assuming target number 15
>> roll = (result, initial_mins, initial_max)

> I'd forget the tuple and just use the names,
> it is more readable that way...

>if result > 15:
>    if initial_mins >= 2:...
>    elif initial_max >=2:...

> But otherwise it seems to reflect the rules as you've written them...
Oh, that's a good idea, that's definitely more readable.

But the issue isn't if it reflects the rules (although it's good that
it does!), but whether there's a better way to structure the
if-elif-else part, or even if there's a better way to handle it. I'll
probably send it through a function, something like (pseudocode):
def check_result(diceroll_result, initial_mins, initial_max):
    check for success/failure and so on
    return result

But even so, is my if-elif-else structure the best way to go about it?

-- 
best regards,
Robert S.


More information about the Tutor mailing list