Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

One Step at a Time

The invoice still needs its last four lines: the number of walks, the month's total, the discount and what's left to pay. Ask for all of them at once, and you get a long answer that may rewrite your program, and if something in it is wrong, it could be anywhere. So, as in Build in Small Steps, ask for a plan first, then for one step at a time, and run each step before you ask for the next. When something goes wrong, it's in the step you've just added.

A plan is quick to read and quick to change. If one of its steps isn't what you want, you've lost nothing, since there's no code yet. Plans differ from answer to answer: some work the total out in a function of its own, and some add a running total to print_weeks(). Any of them works, as long as you understand each step.

Instructions

  1. 1

    Attach script.py and ask for a plan for the invoice's last four lines, Walks, Total, Discount and To pay: the steps in order, without code. Then send it.

  2. 2

    Ask in the same chat for the first step only: a function count_walks(weeks) that returns the number of walks in the month. You don't need to attach the program again, since it hasn't changed.

  3. 3

    Paste the function above the line that prints the heading. Under the line that calls print_weeks(), add count = count_walks(weeks) and a line that prints Walks: and count. Run the program: under the weeks, it prints Walks: 10.

Back

3/6

  1. 1. The Invoice
  2. 2. Tests First
  3. 3. One Step at a Time
  4. 4. What the Test Shows
  5. 5. Feedback on Your Program
  6. 6. Congratulations!
Next

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with: