Skip to content

Commit 4ed2cf0

Browse files
committed
fix: text style
1 parent f765c40 commit 4ed2cf0

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

content/chapter-2/203.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ We highlighted the Copilot logo in the bottom right of figure 2.1 as you should
2424

2525
### 2.3.1 Set up your working folder
2626

27-
In the top of the Activity Bar on the left in VSCode you will find the “Explorer” as the top icon. After you click on the “Explorer”, it should say “No Folder Open.” Click on the button to “Open Folder” and select a folder in your computer (or make a new one—we like the folder name fun\_with\_Copilot). Once you’ve opened this folder, your workspace will be the folder you opened which means you should have your code and any data files, like the one we’ll use later this chapter, in that folder.
27+
In the top of the Activity Bar on the left in VSCode you will find the “Explorer” as the top icon. After you click on the “Explorer”, it should say “No Folder Open.” Click on the button to “Open Folder” and select a folder in your computer (or make a new one—we like the folder name `fun_with_Copilot`). Once you’ve opened this folder, your workspace will be the folder you opened which means you should have your code and any data files, like the one we’ll use later this chapter, in that folder.
2828

2929
> **File not found or file missing errors**
3030
>
@@ -45,7 +45,7 @@ Let’s check to see if we’ve set up everything properly and that Copilot is w
4545

4646

4747

48-
After creating it, we like to make sure that we’ve saved the file. Go to “File -> Save As” and let’s just name this file “first\_Copilot\_program”.
48+
After creating it, we like to make sure that we’ve saved the file. Go to “File -> Save As” and let’s just name this file `first_Copilot_program`.
4949

5050
Next, in the text editor, type:
5151

@@ -105,6 +105,6 @@ To run your program, go to the top right corner of the text editor and press the
105105
Hello Copilot
106106
```
107107

108-
The top line starting with “>” is the command for the computer to run your code and all it says is to run your first\_Copilot\_program.py using Python. The second line is the output from running the command, and it says “Hello Copilot” which is what we’d hoped to see.
108+
The top line starting with `>` is the command for the computer to run your code and all it says is to run your `first_Copilot_program.py` using Python. The second line is the output from running the command, and it says “Hello Copilot” which is what we’d hoped to see.
109109

110110
**Congratulations! You’ve written your first program!** We now know that your programming environment is set up correctly, and we can move onto our first programming task. But before we do, we’d like to go over some tips for how to deal with some common issues we’ve encountered when working with Copilot, so you have these tips available to you when working through the next example.

content/chapter-2/205.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Because you’ve just started working with Copilot, we’re wary of showing you
2323

2424
Also, Copilot will generate a lot of code in this section and we don’t expect you to understand the code until much later in the book. We provide the code solely so you can see what Copilot gave us, but do NOT feel as though you need to try to understand the code in this chapter.
2525

26-
To get started, let’s create a new file. If you aren’t already in VSCode, go ahead and start it. Then create a new Python file and save it as “nfl\_stats”.
26+
To get started, let’s create a new file. If you aren’t already in VSCode, go ahead and start it. Then create a new Python file and save it as `nfl_stats`.
2727

2828
#### Showcasing Copilot’s value in a data processing Task
2929

@@ -56,7 +56,7 @@ game_id,player_id,position ,player,team,pass_cmp,pass_att,pass_yds,...
5656

5757
There are a bunch more columns after these, but these have all we need to perform our first task. We know now that there’s a column for players and a column for passing yards. Aaron Rodgers is a player that gets passing yards in each game that he plays. But how many passing yards does he have in total, over all of the games that he played? This isn’t so easy to answer by directly looking at the file. So what we want the computer to do is to make this easier for us!
5858

59-
We want it to sum up all the passing yards (pass\_yds) for rows (games) where Aaron Rodgers is the player. For now, we’re going to just ask for all the yards in the database even though it covers multiple seasons. We could change this later if we’d like. This problem might be a good problem to give to programmers learning to program in their 4th week of a standard college-level introductory programming course, but we have Copilot! So instead of learning how to write this code from scratch, we’re just going to ask Copilot to generate it for us. To make that happen, we are going to be quite specific in our request to make sure Copilot knows what we are asking for.
59+
We want it to sum up all the passing yards (pass_yds) for rows (games) where Aaron Rodgers is the player. For now, we’re going to just ask for all the yards in the database even though it covers multiple seasons. We could change this later if we’d like. This problem might be a good problem to give to programmers learning to program in their 4th week of a standard college-level introductory programming course, but we have Copilot! So instead of learning how to write this code from scratch, we’re just going to ask Copilot to generate it for us. To make that happen, we are going to be quite specific in our request to make sure Copilot knows what we are asking for.
6060

6161
Specifically, we’re only going to ask it to perform small amounts of work and then re-prompt it to perform the next step. Later we’ll discuss how to write good prompts, but for now, just go ahead and use what we’ve written below by placing this text at the top of your new file:
6262

content/chapter-3/306.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ title: "[译] [XXX] XXXXXXXXXXXXXXXX"
88

99
In this section, we’re going to write a bunch of functions with Copilot. We’ll be coding them entirely in Copilot to help you see the cycle of function design we just described. Although our goal in this chapter isn’t to help you read code just yet, we will be seeing programming features (sometimes called constructs) in the solutions that are very common in code (e.g., if statements, loops) so we’ll point those out when we see them. Then in Chapter 4, we’ll say more about how to read this code in more detail.
1010

11-
Many of the functions we’re about to work on are unrelated to each other. For example, we’ll start with a function about stock share prices and move to functions about strong passwords. You typically wouldn’t store unrelated stuff like this in the same Python file. But as we’re just exploring different examples of good functions, please feel free to store all functions in the same Python file, perhaps named function\_practice.py or ch3.py.
11+
Many of the functions we’re about to work on are unrelated to each other. For example, we’ll start with a function about stock share prices and move to functions about strong passwords. You typically wouldn’t store unrelated stuff like this in the same Python file. But as we’re just exploring different examples of good functions, please feel free to store all functions in the same Python file, perhaps named `function_practice.py` or `ch3.py`.
1212

1313
### 3.6.1 Dan’s stock pick
1414

1515
Dan is an investor in a stock called AAAPL. He purchased 10 shares for $15 each. Now, each of those shares is worth $17. Dan would like to know how much money he has made on the stock.
1616

1717
Remember that we want to make our function as general as possible. If the only thing our function could do is calculate this exact AAAPL situation, it wouldn’t be that useful in general. Sure, it would help Dan right now, but what about when AAAPL’s share price changes again, or when he is interested in another stock entirely?
1818

19-
A useful general function here would take three parameters, all of which are numbers. The first parameter is the number of shares purchased, the second is the share price when the shares were purchased, and the third is the current share price. Let’s call this function money\_made, since it’s going to determine how much money we’ve made or lost on the stock. In general, you want to name your function as an action word or words that describe what your function is doing. With that, we have enough to write the function header:
19+
A useful general function here would take three parameters, all of which are numbers. The first parameter is the number of shares purchased, the second is the share price when the shares were purchased, and the third is the current share price. Let’s call this function `money_made`, since it’s going to determine how much money we’ve made or lost on the stock. In general, you want to name your function as an action word or words that describe what your function is doing. With that, we have enough to write the function header:
2020

2121
```python
2222
def money_made(num_shares, purchase_share_price, current_share_price):
@@ -61,7 +61,7 @@ This way, we can call the function as many times as we like without going throug
6161

6262
At the bottom of the resulting window, you will see three greater-than symbols >>>. This is called a _prompt_, and you’re allowed to type Python code here. (This _prompt_ has nothing to do with the kind of prompt that we use when interacting with Copilot.) It will show us the result of the code that we type right away, which is convenient and fast.
6363

64-
To call our `money\_made` function, we need to provide three arguments, and they will be assigned left to right to the parameters. Whatever we put first will be assigned to `num\_shares`, whatever we put second will be assigned to `purchase\_share\_price`, and whatever we put third will be assigned to `current\_share\_price`.
64+
To call our `money_made` function, we need to provide three arguments, and they will be assigned left to right to the parameters. Whatever we put first will be assigned to `num_shares`, whatever we put second will be assigned to `purchase_share_price`, and whatever we put third will be assigned to `current_share_price`.
6565

6666
Let’s try this! At the prompt, type the following and press enter (or `<shift>+Enter`). Don’t type the >>> as that’s already there, and we are including it throughout the book to make it clear where we are typing. Please see figure 3.5 for an example of running the function in the terminal at the Python prompt.
6767

@@ -78,7 +78,7 @@ You’ll see an output of
7878

7979
Is `20` correct? Well, we bought 10 shares, and each of them went up $2 (from $15 to $17), so we did make $20. Looks good!
8080

81-
> Figure 3.5 Calling the money\_made function from Python prompt in the VSCode Terminal.
81+
> Figure 3.5 Calling the `money_made` function from Python prompt in the VSCode Terminal.
8282
8383
![](chapter-3.files/chapter-339260.png)
8484

@@ -104,7 +104,7 @@ What other tests can we do? Well, sometimes a stock price doesn’t change at al
104104

105105
Looks good!
106106

107-
Testing is a combination of science and art. How many categories of things are there to test? Are these two calls really two different categories? Have we missed any categories? You will improve your testing ability through practice, and we’ll spend all of Chapter 6 talking about testing. For now, it looks like our `money\_made` function is doing its job.
107+
Testing is a combination of science and art. How many categories of things are there to test? Are these two calls really two different categories? Have we missed any categories? You will improve your testing ability through practice, and we’ll spend all of Chapter 6 talking about testing. For now, it looks like our `money_made` function is doing its job.
108108

109109
It’s possible for a function to use variables (rather than just its parameters) in its code, and we want to show you an example of that now so that you’re ready when you see Copilot doing it.
110110

@@ -129,7 +129,7 @@ Unlike our previous functions in this chapter, we’re not dealing with numbers
129129

130130
The Python type for text is called a **string**. There are zillions of possible strings, because we can use a string to store whatever text we want. And the Python type for a yes/no result is called a **Boolean** or **bool**. A bool has only two values: True or False.
131131

132-
Alright! We’re ready to prompt Copilot. For functions that return bool (True/False) values, we usually name the function as has\_x, or is\_x, or using some other verb that implies a true/false result.
132+
Alright! We’re ready to prompt Copilot. For functions that return bool (True/False) values, we usually name the function as `has_x`, or `is_x`, or using some other verb that implies a true/false result.
133133

134134
```python
135135
def is_strong_password(password):
@@ -349,7 +349,7 @@ password = input("Enter a strong password: ")
349349
```
350350

351351

352-
That `while` keyword creates another kind of loop, this one continuing as long as the entered password is not strong. Copilot is also smart enough to call our earlier `is\_strong\_password` function to determine what counts as a strong password. As we will see in future chapters, using functions as building blocks in this way is precisely how large programs are built. You will often notice Copilot calling your earlier functions to solve later ones, much as we observed here.
352+
That `while` keyword creates another kind of loop, this one continuing as long as the entered password is not strong. Copilot is also smart enough to call our earlier `is_strong_password` function to determine what counts as a strong password. As we will see in future chapters, using functions as building blocks in this way is precisely how large programs are built. You will often notice Copilot calling your earlier functions to solve later ones, much as we observed here.
353353

354354
Let’s test this! Highlight all of our password function code and hit `<Shift>+Enter`. We’ll call the function that we want to test. Then, try typing passwords, hitting enter after each one. You’ll notice that it keeps asking you until you finally provide a strong password:
355355

@@ -439,7 +439,7 @@ Let’s try a couple more. In each case, calculate by hand what you expect the a
439439

440440
There are many ways to write correct code for a function. If you press `<Ctrl>+Enter` and look at the Copilot suggestions, you may see different types of code. It doesn’t necessarily mean that one of these types is right and the others are wrong.
441441

442-
For example, here’s another solution for num\_points that we got from the other Copilot suggestions.
442+
For example, here’s another solution for `num_points` that we got from the other Copilot suggestions.
443443

444444
```python
445445
points = {'a': 1, 'e': 1, 'i': 1, 'o': 1, 'u': 1, 'l': 1,
@@ -475,7 +475,7 @@ Return the word worth the most points.
475475
```
476476

477477

478-
How will Copilot know how many points each word is worth? Well, it can call that `num\_points` function that we wrote in the previous section!
478+
How will Copilot know how many points each word is worth? Well, it can call that `num_points` function that we wrote in the previous section!
479479

480480
Here’s the code that Copilot gives us.
481481

content/chapter-4/401.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The second is being able to determine the overall purpose of a program. As profe
1414

1515
At the end of these two chapters, we’ll want you to be able to do both at the level of being able to interpret the code produced by Copilot. We’ll start focusing on that line-by-line understanding but toward the end, you’ll start being able to look at a small chunk of code and determine its purpose.
1616

17-
We can illustrate the difference between these two levels of reading code by referring back to our `best\_word` function from Chapter 3, reprinted in the following listing.
17+
We can illustrate the difference between these two levels of reading code by referring back to our `best_word` function from Chapter 3, reprinted in the following listing.
1818

1919
> Listing 4.1 Best Word function for Scrabble, reprinted from Chapter 3
2020
@@ -35,7 +35,7 @@ Return the word worth the most points.
3535
return best_word
3636
```
3737

38-
A **tracing description** of what this program does would be a description of each line. For example, we would say that we're defining a function called `best\_word`. We have a variable called `best\_word` that we start off as a string with no characters, otherwise known as the empty string. (It’s unfortunate that the function and this variable are both called `best\_word`, because it makes it trickier to refer to one or the other, but that’s what Copilot gave us.) We also have another variable `best\_points` that we start at 0. Then we have a for loop over each word in the `word\_list`. Inside the for loop, we call our `num\_points` helper function... and so on. (We’ll be explaining how we know what each line of code does over the next two chapters!).
38+
A **tracing description** of what this program does would be a description of each line. For example, we would say that we're defining a function called `best_word`. We have a variable called `best_word` that we start off as a string with no characters, otherwise known as the empty string. (It’s unfortunate that the function and this variable are both called `best_word`, because it makes it trickier to refer to one or the other, but that’s what Copilot gave us.) We also have another variable `best_points` that we start at 0. Then we have a for loop over each word in the `word_list`. Inside the for loop, we call our `num_points` helper function... and so on. (We’ll be explaining how we know what each line of code does over the next two chapters!).
3939

4040
In contrast, a **description of the overall purpose** would be something like our docstring description: “Return the word with the highest Scrabble point value from a list of words.” Rather than refer to each line, this description refers to the code’s purpose as a whole, explaining what it does at a high level.
4141

content/chapter-4/402.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ In Chapter 2, when setting up your computer to use GitHub Copilot, you installed
1010

1111
We suspect that, soon, the Copilot Labs extension, or parts of it, will be folded into the main Copilot extension. If that happens, the specific steps we give here may vary somewhat, and in that case, we encourage you to consult more general GitHub Copilot documentation.
1212

13-
For now, with the Copilot Labs extension installed, you can highlight some code that you want Copilot to describe to you. Let's try this with our `best\_word` function.
13+
For now, with the Copilot Labs extension installed, you can highlight some code that you want Copilot to describe to you. Let's try this with our `best_word` function.
1414

1515

1616
> Figure 4.1 The Copilot Labs view in VSCode.
@@ -23,15 +23,15 @@ First, click on the Copilot Labs tab in your Activity Bar (on the left-hand side
2323

2424

2525

26-
Next, highlight all of the code for our best\_word function as is highlighted in figure 4.2. (You may need to have Copilot generate the code for you again if you didn't save it from Chapter 3.)
26+
Next, highlight all of the code for our `best_word` function as is highlighted in figure 4.2. (You may need to have Copilot generate the code for you again if you didn't save it from Chapter 3.)
2727

28-
> Figure 4.2 The code from the `best\_word` function highlighted in the editor.
28+
> Figure 4.2 The code from the `best_word` function highlighted in the editor.
2929
3030
![](chapter-4.files/chapter-48299.png)
3131

3232
After highlighting the code, you should now see the code appear in the left in the EXPLAIN feature as shown in figure 4.3
3333

34-
> Figure 4.3 The code from the best\_word function appearing in Copilot Labs.
34+
> Figure 4.3 The code from the `best_word` function appearing in Copilot Labs.
3535
3636

3737
![](chapter-4.files/chapter-48572.png)

0 commit comments

Comments
 (0)