Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Reading

(3-4h) Reading PDF.

Until p.340, not including Programming exercises.

Concepts:

  • 1. Intro

    • Meaning: group of statements for performing a specific task

    • Divide and conquer

    • void vs value-returning

  • 2. Defining and calling a void function

    • function definition

    • rules for function names

    • calling a function

    • returning of a function

    • indentation

  • 3. Designing a program to use functions

    • flowchart symbol

    • Top-down design

    • Placeholder functions and pass for empty functions

  • 4. Local variables

    • Scope

    • Different functions can have the same variable

  • 5. Passing arguments to Functions

    • Argument (or parameter)

    • Multiple arguments

    • Making changes to an argument inside a function (assignment)

    • keyword arguments

    • order of arguments when mixing keyword arguments with positional ones

    • keyword-only parameters

    • positional-only parameters

    • default arguments

  • 6. Global variables and global constants

  • 7. Intro to value-returning functions: generating random numbers

    • Standard library functions and import

    • Generating random numbers, random.randint()

    • Calling functions from an f-string

    • Generating random numbers in ipython (I use it to generate random numbers during an oral exam 🙂, but use a different seed each time. Otherwise you get the same sequence, e.g.,import random as r; r.seed(); r.randrange(1, 12))

    • Using random numbers to represent other values using randint(BEGIN,END) == BEGIN

    • randrange, random, uniform

    • random number seeds

  • 8. Writing value-returning functions

    • return num1 + num2 instead of result = num1 + num2; return result

    • Using value-returning functions

    • input-process-output (IPO) Chart

    • Example: modularizing with functions

    • returning strings, Boolean values

    • returning multiple values

    • returning None

  • 9. math module

    • sqrt, hypot, sin ...

    • pi, e, ...

  • 10. Storing functions in modules (Creating your own modules)

    • Conditionally executing the main function in a module (if __name__ == '__main__')

  • 11. Turtle: modularizing with functions

    • e.g., square(x, y, width, color)

    • storing functions in a module