Which is better practice for this if elif… else statement? If below piece of code has to be restructured to use but one single if-elif block, which is better? 1. or 2.?



A = int(input(&quot;Enter an integer(1~30): &quot;))




if A % 6 == 0:
    print(&quot;A is even&quot;)
    print(&quot;A is even and a multiple of 6 (6, 12, 18, 24, 30).&quot;)
elif A % 10 == 0:
    print(&quot;A is even&quot;)
    print(&quot;A is even and a multiple of 10 (10, 20).&quot;)
elif A % 2 == 0:
    print(&quot;A is even&quot;)
    print(&quot;A is even and a number out of 2, 4, 8, 14, 16, 22, 26, 28.&quot;)
elif A % 3 == 0:
    print(&quot;A is odd&quot;)
    print(&quot;A is odd and a multiple of 3 (3, 9, 15, 21, 27).&quot;)
else:
    print(&quot;A is odd&quot;)
    print(&quot;A is 1 or a number out of 1, 5, 7, 11, 13, 17, 19, 23, 25, 29.&quot;)





if A % 2 == 0 and A % 3 == 0:
    print(&quot;A is even&quot;)
    print(&quot;A is even and a multiple of 6 (6, 12, 18, 24, 30).&quot;)
elif A % 2 == 0 and A % 5 == 0:
    print(&quot;A is even&quot;)
    print(&quot;A is even and a multiple of 10 (10, 20).&quot;)
elif A % 2 == 0 and A % 3 != 0 and A % 5 != 0:
    print(&quot;A is even&quot;)
    print(&quot;A is even and a number out of 2, 4, 8, 14, 16, 22, 26, 28.&quot;)
elif A % 2 != 0 and A % 3 == 0:
    print(&quot;A is odd&quot;)
    print(&quot;A is odd and a multiple of 3 (3, 9, 15, 21, 27).&quot;)
else:
    print(&quot;A is odd&quot;)
    print(&quot;A is 1 or a number out of 1, 5, 7, 11, 13, 17, 19, 23, 25, 29.&quot;)


This is part of a question in a school assignment and the problem is to reformat some code into the structure of
if
    …
elif
    …
elif
    …
else
    …

There are obviously better structures to avoid multiplicating print(&quot;A is even&quot;) but the question is to format it in the structure above.
So if the two above are the only options which is better and why?
The following is better IMO. Duplicated &quot;A is odd&quot; / &quot;A is even&quot; strings are omitted from the output. They could be added if required.
if A % 2 == 0:
    if A % 6 == 0:
        msg = &quot;a multiple of 6 (6, 12, 18, 24, 30)&quot;
    elif A % 10 == 0:
        msg = &quot;a multiple of 10 (10, 20)&quot;
    else:
        msg = &quot;a number out of 2, 4, 8, 14, 16, 22, 26, 28&quot;
    print(f&quot;A is even and {msg}.&quot;)
else:
    if A % 3 == 0:
        msg = &quot;a multiple of 3 (3, 9, 15, 21, 27)&quot;
    else:
        msg = &quot;a number out of 1, 5, 7, 11, 13, 17, 19, 23, 25, 29&quot;
    print(f&quot;A is odd and {msg}.&quot;)

As for which one of the two versions of the provided code is better, I agree with @stefan's answer.