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 You Know, Where It Runs

Look again at the functions you pasted. They may have had import math and math.ceil(), raise ValueError, or a text in triple quotes under the def line, which you haven't learned. They work, but code you can't read is code you can't check or fix. The AI writes for anyone, as it explains for anyone: tell it what you know, and it makes do with that.

It doesn't know where your program runs either. Most code is written for a computer where a program can wait for typing, read files and load libraries someone has installed. Here, and in many school editors, it can't: input() ends with EOFError, as you saw, a library that isn't installed with ModuleNotFoundError, and a file like this:

file = open("walks.txt")
Traceback (most recent call last):
  File "<exec>", line 1, in <module>
FileNotFoundError: [Errno 44] No such file or directory: 'walks.txt'

Mia wants to see what each of this week's walks cost. The program in the editor has her walks and walk_price(), and its last lines call prices(walks), which doesn't exist yet: it should return a list of the prices, which the program prints and adds up. Asked for it with the program attached, one answer gave:

def prices(walks):
    return [walk_price(minutes) for minutes in walks]

That's right, and it puts a loop inside square brackets, which you haven't learned. The other answers did the same. Say what you know and where the program runs, and you get code you can read, made for the place it runs.

Instructions

  1. 1

    Attach script.py and add to the message what you know and where the program runs: you know variables, lists, if, for loops and functions, and nothing more, and the program runs in the browser, so it can't use input(), files or libraries. Then send it.

  2. 2

    Paste the function in place of the comment and run the program. Keep the line with the walks: the program prints Prices: [6, 12, 6, 12, 18] and Total: 54.

Back

3/6

  1. 1. What Goes In, What Comes Out
  2. 2. Examples Settle What Words Don't
  3. 3. What You Know, Where It Runs
  4. 4. The Form You Need
  5. 5. Quiz: Which Request
  6. 6. Summary
Next

Start programming for free

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

Or sign up with: