Unformatted text preview:

0 Gearing Up Campers welcome to CAMP110 By this point you should be fully geared with your laptop s operating system up to date software installed and workspace ready to go If you have not completed those steps yet please do so before journeying off into this exercise 1 Starting from the Trailhead Before opening up VSCode you will want to be sure Docker Desktop is running on your computer On a Mac you can check this by looking for the whale with boxes icon in your top menu bar On Windows you can check this by looking for the whale with boxes icon in your system tray If you do not see the icon open the Docker Desktop application from your start menu or applications folder Our programming journey begins in Visual Studio Code a free leading text editor designed for software development Go ahead and open Visual Studio Code Once open from the File menu select Open Recent After completing the setup instructions above you should see two entries with comp110 24s workspace Your GitHub Username You want to select the one with Dev Container at the end of it Go ahead and open it up You should be greeted with window that looks like the following if tabs are open in the main part of the window you can close them VSCode Dev Container There are three important parts to recognize in this window you will make use of through the semester 1 In the bottom left corner you should see Dev Container comp110 24s 003 as shown in the photo above If you only see the icon open the VSCode command palette by pressing Ctrl Shift P or Cmd Shift P on Mac and type Reopen in Container This will open the Dev Container and you should see the Dev Container comp110 24s 003 appear 2 In the top left corner you will see an icon with two files that represents the File Explorer Clicking it will open or toggle closed if it is already open a panel that shows the files and directories in your workspace 3 Finally there is a sidebar button with a Play icon and a bug for the Run and Debug panel This panel is where you will start the Trailhead app from You will learn about additional debugging capabilities found in this panel soon 2 Starting Trailhead Open the Run and Debug pane as discussed above and press the green play button You should see a new terminal window open in the bottom of the screen and a message that says Starting Trailhead server at http localhost 1110 appear in a terminal You can close this terminal pane with the X after seeing this message As shown in the video above your next step is to open a web browser Google Chrome is recommended for our course and navigate to http localhost 1110 You should see Trailhead s home page If you do not try the address http 127 0 0 1 1110 instead These two web addresses localhost and 127 0 0 1 refer to your personal computer and the 1110 refers to the port number Trailhead is running on One thousand 110 hopefully a memorable number From the Trailhead home screen your workspace s modules are listed The welcome module refers to the welcome py found in the File Explorer pane of VSCode Opening the py file you can see the code which resulted in the message being displayed in Trailhead We recommend keeping VSCode and your browser with Trailhead open side by side such that you can see both at the same time As you are writing programs you will want to see and interact with the results of your work in the Trailhead browser window 3 Writing Your First Program In Trailhead navigate back to the home page by clicking Trailhead in the navigation In VSCode open the File Explorer pane and right click in the blank space Select New File and name the file ex00 hello world py Double check that the filename exactly matches what is specified here In Trailhead you will see the your new module appear If you click to open it you will see that the module exited without output This is because the file is empty Open the ex00 hello world py file in VSCode and type the following print Hello world Save the file again by pressing Ctrl S or Cmd S on Mac In Trailhead you should see the message Hello world now appear as output This should happen automatically upon saving but you can also manually run the program again with the green Run Again or Rerun button Congratulations You have written your first program in Python For over fifty years it s been a rite of passage for new programmers first program to print Hello world to the screen Wooo You ve taken your first step on the trail to becoming a programmer 4 Writing Your First Function Functions are the most fundamental building block of programming They exemplify the fundamental pattern of taking one or more input values processing them in an algorithm and returning a result You will be learning a lot about functions this week and building upon this knowledge throughout the course For now let s write a function that takes a name as an input parameter and returns a string that greets the person by name In VSCode go ahead and delete the previous print statement that printed Hello world to output Add the following function definition to your ex00 hello world py file Note that the second and third lines are indented this formatting is important def greet name str str A welcoming first function definition return Hello name When you save the file in Trailhead you will see that the module once again exits without output That is OK We have defined a function but we have not yet called it Let s do that now In Trailhead switch to the Interact tab This tab allows you to interact with your Python module using what is known as a REPL short for a Read Evaluate Print loop From the Interact tab you will see the greet function you defined listed in Globals Let s try making use of this function In the text box try typing the following function call expression and pressing enter greet name Campers Try typing another function call expression but this time put your name in the quotes For example if your name is Kris you would type greet name Kris Feel free to try calling the function with other names as well Your interactions should look something like this greet REPL Interactions Hi I m Theo the Thorough Turtle I m here to help you slow down and think through the details of what you are learning step by step I ll be popping up throughout the course as a reminder to zoom in on some of the beautifully nitty gritty details of programming At times this can feel tedious but when you understanding and appreciate the details you will have the confidence to take on bigger challenges Let s


View Full Document

Notes

Download Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?