Summary by TwinMind · 1h 3m 30s
Summary by TwinMind · 1h 3m 30s

Lecture 1: Introduction to CS and Programming Using Python

Lecture 1: Introduction to CS and Programming Using Python

MIT OpenCourseWare

MIT OpenCourseWare

Course Introduction and Administrative Information

  • Course: 6100L (new number), Introduction to Programming
  • Instructor: Anna Bell (first name Anna, last name Bell), EECS department lecturer ~10 years
  • Full semester version of 6100a
  • Lecture format: teaching + interactive Q&A + coding breaks ("utri breaks")
  • Emphasis on participation and practice - programming is a skill requiring repetition
  • Download slides beforehand for note-taking and coding along

Learning Objectives and Course Structure

  • Three main outcomes: knowledge of concepts, programming skills, problem solving skills
  • Lectures/exams: test conceptual knowledge
  • Finger exercises: develop programming skills
  • Problem sets: develop problem solving skills (English problem → CS concepts → programming)
  • Topics covered:
    • Computational thinking
    • Python programming language
    • Code organization and structure
    • Basic algorithms
    • Algorithmic complexity and efficiency

Knowledge Types: Declarative vs Imperative

  • Declarative knowledge: statements of fact (e.g., "square root of X is Y such that Y*Y = X")
  • Imperative knowledge: recipes/how-to instructions
  • Programming = writing recipes for computers
  • Example: finding square root of 16
    • Initial guess: 3
    • Step 1: if 3*3 close enough to 16, stop; otherwise continue
    • Step 2: new guess = average of G and X/G = (3 + 16/3)/2 = 4.17
    • Step 3: repeat until close enough
    • Final result: ~4.00 (within acceptable tolerance)

Algorithms and Computer Architecture

  • Algorithm components:
    • Sequence of steps
    • Flow of control (if/then, repeat)
    • Stopping condition
  • Computers: machines that execute algorithms
    • Good at: storing lots of data, fast operations
    • Limitations: not smart, only follow instructions exactly
  • Brief history:
    • Pre-1940s: fixed program computers (calculators)
    • Post-1940s: stored program computers with interpreters
  • Basic computer components:
    • Memory (stores values at locations)
    • Arithmetic Logic Unit (ALU) - performs operations
    • Control unit with program counter
  • Example low-level operations: add values at memory locations 3456 and 3457, store at 3458

Programming Language Fundamentals

  • Alan Turing: anything computable in one language is computable in any other
  • Six basic primitives: move tape left/right, read/write/erase value, no operation
  • Programming language structure parallels with English:
    • Primitives: numbers, character sequences, operators
    • Syntax: valid combinations (object operator object)
    • Static semantics: meaningful combinations
    • Semantics: single meaning (unlike English ambiguity)
  • Error types:
    • Syntactic: spelling, indentation
    • Static semantic: type mismatches
    • Semantic: program runs but produces wrong result

Python Objects and Types

  • Programming = creating and manipulating objects
  • Objects have types that determine allowed operations
  • Scalar (primitive) types:
    • int: integers (5, 0, -100, 1000000)
    • float: real numbers (3.27, 2.0, -3.14159)
    • bool: Boolean values (True, False)
    • NoneType: special value None
  • Type checking: use type() command
  • Type casting: convert between types
    • float(3) → 3.0
    • int(5.2) → 5 (truncates, doesn't round)
    • round(5.9) → 6 (rounds then casts to int)

Expressions and Operations

  • Expression syntax: object operator object
  • Python evaluates expressions to single values, stores values not expressions
  • Mathematical operations:
    • +, -, * : result type depends on operands (int if both int, float if any float)
    • / : always returns float
    • // : floor division (integer portion)
    • % : modulo (remainder)
    • ** : exponentiation
  • Operator precedence: exponentiation, then *//%, then +/-
  • Can use parentheses to override precedence

Variables and Assignment

  • Variables: names bound to values (different from mathematical variables)
  • Assignment syntax: variable = expression
  • Process: evaluate right side first, then bind result to left side variable
  • Variable naming rules and best practices:
    • Use descriptive names
    • Avoid single letters
    • Include comments for code chunks
  • Assignment vs equality: = is assignment, not mathematical equality

Memory and Variable Binding

  • Variables can be rebound to new values
  • Example: radius = radius + 1
    • Evaluates right side: current radius value + 1
    • Binds result to radius variable
    • Loses previous binding
  • Line-by-line execution: no automatic recalculation
  • Python Tutor: useful tool for step-by-step code visualization

Practical Examples

  • Circle calculations with pi, radius, area, circumference
  • Unit conversion (meters to feet)
  • Variable swapping problem:
    • Incorrect: x=y, y=x (loses original x value)
    • Correct: temp=y, y=x, x=temp (uses temporary variable)

Key Programming Concepts

  • Computers only do what you tell them
  • Programs execute line by line sequentially
  • Objects have types that determine allowed operations
  • Expressions evaluate to single values
  • Variables provide readable names for values
  • Assignment is binding, not equality