Oct 11: Using Visual Studio Code
Learning Objectives
After today's class, you should be able to:
- Use VS Code to run, debug, and auto-format Python programs.
- Explain the purpose of the idiom
if __name__ == "__main__"
. - Describe several built-in modules, such as
random
andturtle
.
Announcements¶
- Mid-Eval Canvas survey – TODAY
- Ch 8 on zyBooks – due Tuesday
- Only 5 sections this week!
- PA 1 FlexDoko (modules + testing)
- Part A due Tuesday 10/22 (30 pts)
- Part B due Tuesday 10/29 (70 pts)
VS Code Tutorial¶
[30 min]
- Visual Studio Code Setup
- If you are absent today, complete this tutorial on your own
- Bring your completed VS Code setup to class next Monday
Lecture / Demo¶
[20 min]
Part 1¶
- Value of the built-in variable
__name__
- When running
move.py
- When running
stop.py
- When running
- Purpose of
if __name__ == "__main__":
move.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 |
|
stop.py | |
---|---|
1 2 3 4 |
|
Part 2¶
- Python's built-in turtle module
draw.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Exercise
For each outcome, describe the type of edit(s) necessary to draw.py
and move.py
:
- A blue turtle
- A longer simulation
- A smaller range of angles (e.g., -45 to 45) that define the direction of the turtle
- A random range of integers (e.g., 10 to 20) that define the length of a turtle move
- Produce the same outcome as #4 using
forward(move.length())
instead of10
.