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
Attach
script.pyand add to the message what you know and where the program runs: you know variables, lists,if,forloops and functions, and nothing more, and the program runs in the browser, so it can't useinput(), files or libraries. Then send it. - 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]andTotal: 54.