Learning Objectives

Through readings, lecture and labs, it is expected that you are doing work and seeking help to keep pace with the below objectives:

Functions
Over the next several weeks, you should be comfortable with:
  • Calling functions that other people have written
  • Differentiating beween parameters and return values
  • Tracing the execution of programs that use functions
  • Defining simple functions based on descriptions
Note: Functions are SUPER important. Take the time to understand them now, because these ideas are not going away.

Required Reading


Supplemental Materials

We all need alternative presentations of the concepts from time to time. The following resources are optional. If something seems unclear after class, or the pratice questions seem hard for you, then explore these topics more using the resources below.

Functions

Practice

For all these exercises, I recommend you try them on paper and then test them out with PythonTutor.

Exercise 1

Write what this code produces, exactly. Be very careful with whitespace and the newlines.

L = ['Darwin', "Charlie Brown's", 'The Kitchens']
P = L[1:]
print("Lets go to ", end='')
for i in range(len(P)):
    print(P[i], end='')
    if i < len(P)-1:
        print(' or ', end='')

Exercise 2

Write what this code produces, exactly. Be very careful with whitespace and the newlines.

s = ''
for x in ['c', 'a', 't']:
    s = x + s + x
print(s)

Exercise 3

Write what this code produces, exactly. Be very careful with whitespace and the newlines.

A = [-1, 5, 3, -5]
B = A
C = A[:]
B[0] = sum(A)
C[2] = sum(A)
print(B)
print(C)

Exercise 4

Write what this code produces, exactly. Be very careful with whitespace and the newlines.

A = 'ours is not to reason why'
B = A.split()
print(A[2:])
print(B[2:])
print(B[2][:2])

Exercise 5

Write a piece of code that prompts the user for 10 integers, saves these into a list and, afterwards, prints the sum of the numbers in that list.

Here is a sample answer, when you think you have solved it. (Don't cheat yourself and look early).