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

The Price of a Walk

Time for a small project. In this checkpoint, you'll build Mia's price list with the assistant, using what the lessons so far taught: get code explained, say what the code should do, run it before you trust it, and find mistakes with the AI. The instructions say what to do and what should come out, and leave more of the how to you.

The program grows over four exercises, and each one continues where the previous one ended: the editor starts with the program as it should be after the previous step, which may look different from yours. That's fine.

Mia charges £6 for every started half hour: 30 minutes cost £6, 31 minutes cost £12, because the second half hour has started, and 60 minutes still cost £12. The program in the editor prints her prices for 30, 45 and 60 minutes, but the function that works them out isn't there yet, so running it ends with an error:

Traceback (most recent call last):
  File "<exec>", line 4, in <module>
NameError: name 'walk_price' is not defined

The message in the chat box asks for it the way most people would. Sent as it is, it gets what a vague request gets: prices the AI makes up, in a program that asks for the walk with input(), which can't run here. So describe the function instead: its name, what goes in and what comes out, Mia's rule with examples that settle the boundary, and that you want only the function.

The function you get may not look like the one you know: the answers we got worked out the number of half hours as (minutes + 29) // 30 or -(-minutes // 30), both right and neither something you've learned. Ask about a line like that with a number if you want to understand it. Whether it's right, the program tells you when you run it.

Instructions

  1. 1

    Replace the message in the chat box with a description of the function: it's called walk_price, it takes the minutes of a walk and returns Mia's price for it. Say her rule and give examples that settle the boundary, such as 30, 31 and 60 minutes. Ask for only the function, without input(). Then send it.

  2. 2

    Copy the function with the button that copies a block of code, and paste it into the editor between the comment at the top and the lines that print the prices. Keep the three lines that print the prices as they are: the exercise also runs the program with other walks. Run it. It prints 30 min: 6, 45 min: 12 and 60 min: 12.

Back

1/4

  1. 1. The Price of a Walk
  2. 2. Three Dogs
  3. 3. The Mistake in the Discount
  4. 4. Saturday
Next

Start programming for free

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

Or sign up with: