Introduction to Programming (Lecture 1)

Jul 8, 2024

Introduction to Programming - Lecture 1

Instructor Introduction

  • Professor Name: Anna Bell (first name: Anna, last name: Bell)
  • Background: Lecturer for nearly 10 years in the ECS department. Experienced in teaching introductory courses.

Course Overview

  • Course Number: 6100L
  • Focus: Introduction to programming using Python.
  • Goals: Participation, practice, building programming skills, problem-solving, and understanding computer science concepts.
  • Resources: Lecture slides, handouts, and a variety of external resources.

Key Learning Areas

  • Computational Thinking: Approach to problem-solving using computation.
  • Python Programming Language: Basics and advanced concepts.
  • Code Structuring: Writing neat, readable, and modular code.
  • Algorithms: Basic foundational algorithms for solving problems.
  • Algorithmic Complexity: Understanding program efficiency in terms of speed and memory.

Course Structure

  • Interactive Lectures: Coding along with the lecture, opportunities to practice with breaks.
  • Finger Exercises: Programming practice within the class to build programming skills.
  • Problem Sets: Real-world problem-solving exercises combining computer science concepts and Python programming skills.
  • Exams and Quizzes: Testing the knowledge of concepts.

Computers and Algorithms

  • Computers: They follow a set of instructions (or algorithms) to perform tasks. Computers store data and carry out operations but are not inherently smart.
  • Algorithm: Recipe
    • Sequence of steps to achieve a task
    • Flow of control (conditional and repetitive steps)
    • Stop condition

Example: Finding Square Root

  1. Start with an initial guess (e.g., 3 for square root of 16)
  2. Apply iterative steps until reaching the desired precision
  3. Example: Guess, recalculate, and compare
  4. Result: Approximation of the square root

Programming Language Evolution

  • Fixed Program Computers (Pre-1940s): Like pocket calculators, limited to specific tasks.
  • Stored Program Computers: Capable of storing and executing sequences of instructions.
  • Interpreters and High-Level Languages: Made programming more accessible and flexible.
  • Important Figures: Alan Turing demonstrated that any computable problem could be solved using a basic set of primitives.

Python Basics

  • Primitive Types: Integers, Floats, Booleans, and NoneType
  • String: Sequence of characters enclosed in quotes
  • Syntax and Semantics: Importance of proper syntax and static semantics
  • Expressions: Combine objects using operators to form meaningful calculations
  • Type Casting: Converting objects between different primitive types

Example Operations

float(3)         # Converts integer 3 to float 3.0
int(5.2)         # Converts float 5.2 to integer 5
round(5.9)       # Rounds 5.9 to 6

Expression Examples

  • Evaluations and Precedence
3 + 2           # Results in 5
4 + 2 * 6 - 1   # Results in 35 (accounting for operator precedence)

Variables and Assignments

  • Variables: Names bound to values for easier manipulation and readability
  • Assignment Operator (=): Binds names to values (different from mathematical equality)
  • Rules: Dumb, Line-by-Line Execution: Computers follow instructions as given without assumptions

Example of Rebinding

pi = 3.14
radius = 2.2
area = pi * (radius ** 2)
radius = radius + 1  # Rebinds radius from 2.2 to 3.2

Python Tutor Tool

  • Python Tutor: A visual tool to step through code execution and see variable changes in memory.

Summary of Key Points

  1. Object Types: Understanding and manipulating different types of objects (integers, floats, strings, and booleans).
  2. Expressions: Forming and evaluating expressions to yield values.
  3. Variables: Creating and manipulating variables to store and use values in the code.
  4. Computers Follow Instructions: Step-by-step execution of code.
  5. Next Steps: Introducing decision-making and control flow in code for more complex programs.