CS110: Spring 2020

Intro to Computer Programming with Python

CS110: Spring 2020

Schedule > 3. Introduction to Functions

Week 3: Tue, Apr 14

The next two lessons will primarily be dedicated to functions. In this lesson, we will review several different concepts. First, we will go over how to use the command line in order to run our Python files. Next, we will introduce two new data types in the “sequence family” – lists and tuples – which we will use in HW2 and in this week’s tutorial. Finally, we will introduce functions, including some basic terminology and why they are useful. We’ll also take a look at some examples of how to use built-in functions. In the next lesson (Lesson 4), we will practice building our own functions and modules.

This week’s tutorial (Tutorial 1) and homework (Homework 2) will be based on content reviewd in this lesson and the next one. You are strongly encouraged to review the content in these lessons before trying the tutorial/homework.

Please Complete the Following Tasks

1. Download the Exercise Files

Exercise Files

2. Review the Slides

  1. The Command Line
  2. Working with Functions & Modules
  3. Supplementary Slides for Live Lecture

3. Watch the Lecture Video(s)

Link Title Type Duration
Video 1 Demo: Working with the Command Line pre-recorded 12:40
Video 2 Demo: 3 Ways to Execute Python pre-recorded 05:59
Video 3 Lists & Tuples pre-recorded 10:16
Video 4 Expressions & Intro to Functions pre-recorded 10:33
Video 5 More Function Rules pre-recorded 11:22
Video 6 Built-In Functions pre-recorded 09:24
Video 7 Practice with Built-In Functions lecture 01:33:20

4. Review / Study the Supplemental Materials

Note: these readings / videos are suggested for additional context / examples, but not required.

  1. Severance Ch4: Functions.
    readingvideo
  2. Heinold Ch4: Functions.
  3. Heinold Ch12: Modules.
    Skim sections 12.1 through 12.4.

5. Review the command line Cheatsheet

For your convenience, we have made you a little cheatsheet to help you get familiar with the command line. Django Girls is a good resource. Note: you will not be tested on this or anything, but navigating the command line can be useful.

  DOS (Windows) Shell (Mac / Linux)
What directory am I in? > cd $ pwd
Change directories > cd $ cd
List files & directories > dir
> tree # lists subdirectories
$ ls
$ ls -l
Navigate to parent directory > cd .. $ cd ..
Navigate into child directory > cd cs110 $ cd cs110
Navigate into descendant directory > cd lectures\lecture_03 $ cd lectures/lecture_03
Navigate to sibling directory > cd ..\lecture_02 $ cd ../lecture_02
Navigate to ancestor directory > cd ..\..\ $ cd ../../
Navigate to home directory   $ cd
Command history > doskey /HISTORY $ history

Other optional commands you may find useful…

  DOS (Windows) Shell (Mac / Linux)
Create a new file > echo . > my_file.txt $ echo . > my_file.txt
$ touch my_file.txt
Append to a file > echo "some text" >> my_file.txt $ echo "some text" > my_file.txt
Save history to a file > doskey /HISTORY > my_history.txt $ history > my_history.txt
Move a file > move my_history.txt Documents/. $ mv my_history.txt Documents/.
Make a folder > mkdir my_folder $ mkdir my_folder
Delete a file > del my_history.txt $ rm my_history.txt
Delete a folder > rmdir my_folder $ rm -r my_folder