refactor(nav): extract print_plan()
This commit is contained in:
parent
803edd6f86
commit
515e055375
1 changed files with 10 additions and 5 deletions
15
nav.py
15
nav.py
|
|
@ -64,6 +64,15 @@ def plan(destination):
|
|||
return route, total, total / CRUISE_SPEED, fuel
|
||||
|
||||
|
||||
def print_plan(destination):
|
||||
"""Print the flight plan for a destination."""
|
||||
route, total, days, fuel = plan(destination)
|
||||
print("Route: " + " -> ".join(NAMES[w] for w in route))
|
||||
print(f"Distance: {total:.1f} million km")
|
||||
print(f"Travel time: {round(days)} days")
|
||||
print(f"Fuel required: {round(fuel)} t")
|
||||
|
||||
|
||||
def main():
|
||||
if sys.argv[1] == "--list":
|
||||
for key in sorted(ROUTES):
|
||||
|
|
@ -73,11 +82,7 @@ def main():
|
|||
if destination not in ROUTES:
|
||||
known = ", ".join(sorted(ROUTES))
|
||||
sys.exit(f"Unknown destination: {destination} (known: {known})")
|
||||
route, total, days, fuel = plan(destination)
|
||||
print("Route: " + " -> ".join(NAMES[w] for w in route))
|
||||
print(f"Distance: {total:.1f} million km")
|
||||
print(f"Travel time: {round(days)} days")
|
||||
print(f"Fuel required: {round(fuel)} t")
|
||||
print_plan(destination)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Reference in a new issue