What Goes In, What Comes Out
In Get Code Explained, you asked about code you had. Now you'll ask for code you don't have yet. The assistant writes it in seconds; the hard part is getting code that does what you need. It doesn't know Mia's prices, your program or what you've learned, and whatever you leave out, it fills in with a guess.
The message in the chat box is how many people start. Sent like that, one answer began:
I'll write a simple, self-contained Python program that calculates dog walking prices. It supports different walk durations, multiple dogs, discounts for recurring bookings, and extra fees, and it prints an itemized quote.Then came a program of over 200 lines, with prices nobody had told it ($20 for 30 minutes, 10% extra at weekends) and with input(), which you haven't learned: it waits for someone to type a value while the program runs. The same message gets a different answer each time, but the others were much like this one. A program here gets nothing typed in, so input() ends it at once with an error:
minutes = int(input("Walk length in minutes: "))Walk length in minutes:
Traceback (most recent call last):
File "<exec>", line 1, in <module>
EOFError: EOF when reading a lineEven where input() works, that program isn't Mia's, and it doesn't fit yours. The program in the editor needs one function, walk_price, which it calls three times. A message that gets that function says:
- what goes in: the length of a walk in minutes;
- what comes out: the walk's price, which the function returns;
- the name your program calls:
walk_price(minutes); - what only you know: Mia charges £6 a half hour.
Instructions
- 1
Send the message as it is and look at the answer: which prices did the AI choose, and where do the minutes come from? Then ask in the same chat for a Python function
walk_price(minutes)that takes the length of a walk in minutes and returns its price, and say that Mia charges £6 a half hour. Send it. - 2
Copy the function from the answer and paste it in place of the comment at the top of the program. Keep the three lines that print, and run it: you get the prices of walks of 30, 60 and 90 minutes,
Price: 6,Price: 12andPrice: 18, or6.0,12.0and18.0, which is the same. If the answer's code also prints examples of its own, their lines come first.