Code style query: multiple assignments in if/elif tree
Marko Rauhamaa
marko at pacujo.net
Mon Mar 31 11:40:42 EDT 2014
Chris Angelico <rosuav at gmail.com>:
> Call this a code review request, if you like. I'm wondering how you'd
> go about coding something like this.
As a simple layout question, I'd do it like this:
========================================================================
if mode == "Brake2":
# Already got the brakes fully on
distance_to_full_braking_power = 0.0
speed_full_brake = curspeed
elif mode == "Brake1":
# The brakes went on one second ago, they're nearly full
distance_to_full_braking_power = curspeed - 0.2125
speed_full_brake = curspeed - 0.425
else:
# Brakes aren't on.
distance_to_full_braking_power = (curspeed - 0.1) + (curspeed - 0.4125)
speed_full_brake = curspeed - 0.625
# If we hit the brakes now (or already have hit them), we'll go another
# d meters and be going at s m/s before reaching full braking power.
========================================================================
Marko
More information about the Python-list
mailing list