Lecture Notes: Introduction to Computer Science with Python (600L)
Introduction
- Lecturer: Anna Bell (ECS Department, teaching for almost 10 years)
- Course Overview: Full semester version of 6.100a
- Focus: Course administration, thoughts about computers, Python basics
Course Structure
- U-Try Breaks: Interactive coding opportunities during lectures.
- Emphasis on practice and participation.
- Aim: To develop programming skills, problem-solving abilities, and knowledge of concepts.
Learning Objectives
- Knowledge of Concepts: Learn computer science ideas.
- Programming Skill: Hands-on coding practice.
- Problem-Solving Skills: Apply computer science concepts to solve problems.
Topics Covered
- Computational Thinking: Approach problems computationally.
- Python Programming Language: Basics, structure, and organization of code.
- Algorithms: Base algorithms for future studies.
- Algorithmic Complexity: Efficiency of programs and memory usage.
Knowledge Types in Computer Science
- Declarative Knowledge: Statement of facts.
- Imperative Knowledge: Recipes or instructions.
Example: Finding Square Roots
- Algorithm Steps: Sequence of steps to find the square root of a number, e.g., 16.
- Make an initial guess.
- Average guess and target number.
- Repeat until close enough.
- Key takeaway: Algorithms are structured instructions for computers.
Understanding Computers
- Computers execute algorithms: they are not inherently smart and only follow instructions.
- Brief History: Shift from fixed program computers (1940s) to stored program computers.
Python Basics
- Objects: Created and manipulated in programming. Each object has a type.
- Types: Integer, Float, Bool, NoneType.
- Example of scalar objects (basic types) and non-scalar (structured types).
- Casting Types: Change type without altering the original object.
Expressions and Operators
- Expressions evaluate to one value. Operator precedence is crucial.
- Basic operators:
+
, -
, *
, /
, //
(floor division), %
(modulus), **
(exponentiation).
Variables and Assignments
- Variables: Names for objects that store values.
- Assignment: Binding a value to a variable; not the same as equality in mathematics.
- Variable Naming Rules: Should be descriptive and meaningful.
Code Example
pi = 3.14159
radius = 2.2
area = pi * radius ** 2
Important Concepts
- Line-by-line Execution: Code runs in sequence; reassigned values do not automatically update previous calculations.
- Python Tutor: Useful tool for stepping through code to visualize variable states.
Summary
- Objects: Created and manipulated in Python with specific types.
- Expressions: Combine objects to evaluate to a single value.
- Variables: Named bindings to values allow for better readability.
- Assignment vs. Equality: Understanding the difference is crucial.
- Next lecture will introduce decision-making in programs.
Questions and Engagement
- Encourage questions and participation throughout the course.
- Participate in coding exercises and use discussion opportunities to clarify doubts.