livepython.net

146. Python Program to Break a Long Line of Code (PEP 8)

MediumSpacing

Overview

Two lines in this program are wider than PEP 8 allows. Break them the clean way: inside brackets.

Problem Statement

The starter code reads three prices and prints the order total, with a delivery fee of 40 added. For example, for 100, 250 and 75:

Your order total, including the delivery fee, is: 465

Rewrite it in PEP 8 style:

  • every line at most 79 characters: break the long lines inside brackets, and indent the extra lines,
  • one space around = and +, and one after every comma,
  • but no spaces around the = of the default value delivery_fee=40,
  • two blank lines after the function.

Keep the printed text exactly the same: don't break the string itself. Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

The tests check only the output, and the starter code already prints the right thing. So count your line lengths yourself (most code editors show the column number at the bottom).

Input

One value per line, in this order. Example:

100
250
75

Output

The output for that example:

Your order total, including the delivery fee, is: 465

The tests try 3 different inputs.

Learn this firstChapter 16 · Python Indentation, Spacing and Line Length (PEP 8)
solution.py
def total_with_delivery(first_price,second_price,third_price,delivery_fee = 40):
    return first_price+second_price+third_price+delivery_fee
first_price=int(input())
second_price=int(input())
third_price=int(input())
print("Your order total, including the delivery fee, is:",total_with_delivery(first_price,second_price,third_price))

EXPECTED OUTPUT

1Your order total, including the delivery fee, is: 465

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.