6.100L | Fall 2022 | Undergraduate

Introduction to CS and Programming using Python

Lecture 7: Decomposition, Abstraction, Functions

Topics: Functions: decomposition, abstraction, specifications

Lecture Notes

Lecture 7: Decomposition, Abstraction, Functions

Lecture 7 Code

Readings

Ch 4.1–4.2

Finger Exercise Lecture 7

Question 1: Implement the function that meets the specifications below:

def eval_quadratic(a, b, c, x):
    """
    a, b, c: numerical values for the coefficients of a quadratic equation
    x: numerical value at which to evaluate the quadratic.
    Returns the value of the quadratic a×x² + b×x + c.
    """
    # Your code here

# Examples:    
print(eval_quadratic(1, 1, 1, 1)) # prints 3

Question 2: Implement the function that meets the specifications below:

def two_quadratics(a1, b1, c1, x1, a2, b2, c2, x2):
    """
    a1, b1, c1: one set of coefficients of a quadratic equation
    a2, b2, c2: another set of coefficients of a quadratic equation
    x1, x2: values at which to evaluate the quadratics
    Evaluates one quadratic with coefficients a1, b1, c1, at x1.
    Evaluates another quadratic with coefficients a2, b2, c2, at x2.
    Prints the sum of the two evaluations. Does not return anything.
    """
    # Your code here

# Examples:    
two_quadratics(1, 1, 1, 1, 1, 1, 1, 1) # prints 6
print(two_quadratics(1, 1, 1, 1, 1, 1, 1, 1)) # prints 6 then None

6.100L Finger Exercises Lecture 7 Solutions

Recitation 3

Recitations were smaller sections that reviewed the previous lectures. Files contain recitation notes and worked examples in code.

Recitation 3 Notes and Code

Course Info

Instructor
As Taught In
Fall 2022
Learning Resource Types
Lecture Videos
Lecture Notes
Problem Sets
Programming Assignments with Examples
Readings
Recitation Notes