- Create a new file named prime.py. Create it via the same process as we used in Lab 2 by entering the line below in the terminal.
code prime.py
- Start typing a function definition as below
def is_prime(n):
- Leave the cursor at the end of the line.
-
Hit Ctrl+Enter to see options
-
Pick one of the options that is longer and/or more complex (if there is one) and Accept suggestion #. If there's not one that's longer/more complex, just pick an alternative one and Accept suggestion #.
- Highlight the code and select the Chat extension icon to open the chat window. Tell Copilot to simplify the code by typing in the chat window.
simplify
- Hover over the simplified text and tell Copilot to insert the suggestion at the cursor to replace the text that's currently there.
- Now, let's introduce an error into the code to see how Copilot can fix it. Pick an instance of a variable name and change it to one that doesn't exist. For example, change an instance of "n" to "x".
- Notice the light bulb icon that has popped up. Click on that, scroll to the bottom (if needed), and you'll have additional options to fix or explain with Copilot.
-
Go ahead and click on the "Fix using Copilot" option.
-
After a few moments, it should propose a fix that you can just accept (via the Accept button). You can also click on the Show Changes icon to see before/after for the proposed changes. (If it doesn't propose a fix in the dialog, you can skip to step 12 and use the /fix command in chat instead.)
- (Optional) If you'd like, you can go back and make the error again, highlight the code, and then use the /fix command in the chat window to get the same results.