Skip to content

Task 1 of Meltdown Mitigation is misleading #2535

@punkstarman

Description

@punkstarman

One of the most common blunders a novice can make is to use if-elif-else blocks instead of using a single return statement.

For instance

if a:
    return True
elif b:
    return True
else:
    return False

should simply be written

return a or b

The introduction sets up using if:elif:else: blocks. I fear that a novice will blindly fall into the trap of solving task 1 using an if.

def is_criticality_balanced(temperature, neutrons_emitted):
    if temperature < 800 and neutrons_emitted > 500 and temperature * neutrons_emitted < 500_000:
        return True
    else:
        return False

or something even worse, when it should be solved with a single return statement.

def is_criticality_balanced(temperature, neutrons_emitted):
    return temperature < 800 and neutrons_emitted > 500 and temperature * neutrons_emitted < 500_000

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions