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

What the Test Shows

The next step of the plan is the month's total. For it, someone got the function month_total() in an answer, and it's in the program now, with the two lines that print the total. Asked for it, the AI usually writes a correct one. This answer wasn't correct, and it's the kind of mistake a test is for. Run the program: it prints Total: 90.

That looks believable, and the program runs without an error. But add up the weeks on the invoice: 30 + 24 + 24 + 18 = 96. One of the two numbers is wrong, and working it out by hand, as in Tests Come First, tells you which. Write what you worked out as a test, and it checks the function every time you run the program.

A failed test tells you that something is wrong, but not what. That's a question for the AI, as in Finding Mistakes with AI, and the AI needs the program to answer it: attach it with what it printed, and say what you expected. Ask which line to change rather than for a new program. You see what the mistake was, and the rest of your program stays as it is.

Instructions

  1. 1

    At the end of the program, add a test: print(month_total(weeks) == 96). Run the program: the test prints False.

  2. 2

    Click Attach to message on the console to attach what the program printed, and the same button over the program to attach script.py. Say that your test of month_total() prints False because the total is 90, not 96, and ask which line to change. Then send it.

  3. 3

    Make the change in month_total() and run the program: the invoice says Total: 96, and your new test prints True.

Back

4/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: