Skip to main content
Back

Introduction to Computing and Python Programming: Key Concepts and Methods

Study Guide - Smart Notes

Tailored notes based on your materials, expanded with key definitions, examples, and context.

Introduction to Computing

What is Computer Programming?

Computer programming is the process of creating a sequence of instructions and decisions that a computer can execute to perform specific tasks. It is both a technical and creative activity, requiring logical thinking and problem-solving skills.

  • Definition: A program is a sequence of instructions and decisions designed to solve a problem or perform a computation.

  • Computational Thinking: Learning to program helps develop the ability to think algorithmically and solve problems step by step.

  • Goal: Programming enables you to make computers perform tasks according to your requirements.

Programming Languages

Levels of Programming Languages

Programming languages are the means by which humans communicate instructions to computers. They exist at various levels of abstraction:

  • Machine Language: The lowest-level language, directly understood by the microprocessor, but difficult for humans to read or write.

  • High-Level Languages: Languages like Python, Java, C++, and Visual Basic use instructions that are more understandable to humans, such as print and input statements.

Choosing a Programming Language

There are hundreds of programming languages, each with strengths suited to particular applications.

  • MATLAB: Good for manipulating vectors and matrices.

  • C: Good for writing programs that control data networks.

  • PHP: Good for building websites.

  • Python: Excellent general-purpose language, widely used in education and industry.

Why Python?

Features and Advantages of Python

Python is a popular programming language, especially for beginners, due to its simplicity and versatility.

  • Easy and Clear Syntax: Python code is readable and concise, making it accessible for new programmers.

  • Standard Library: Python comes with a wide range of built-in modules and tools for various tasks.

  • Cross-Platform: Python runs on Windows, Mac, and Linux operating systems.

  • Widely Used: Python is used by major software companies and in many fields, including web development, data science, and automation.

  • Interpreted Language: Python code is executed line by line by an interpreter, which makes testing and debugging easier.

How Computers Execute Programs

Compilers vs. Interpreters

Programs written in high-level languages must be translated into machine code for execution. This can be done using either a compiler or an interpreter.

Interpreter

Compiler

Translates one statement at a time into machine code.

Scans and translates the entire program into machine code at once.

Analysis time is short, but execution is slower overall.

Analysis time is longer, but execution is faster overall.

Does not generate intermediate object code; uses less memory.

Generates object code, which requires more memory and linking.

Errors are reported line by line, making debugging easier.

Errors are reported after scanning the whole program; debugging is harder.

Used by languages like Python and Ruby.

Used by languages like C and C++.

Software Development Life Cycle

Phases of Software Development

Developing a program involves several key steps, often referred to as the software development life cycle:

  1. Analyze: Define and understand the problem to be solved.

  2. Design: Plan a logical sequence of steps (algorithm) to solve the problem.

  3. Code: Translate the algorithm into a programming language.

  4. Test and Correct: Find and fix errors (debugging) in the program.

  5. Document: Organize and describe the program for future reference and maintenance.

Algorithms and Problem Solving

What is an Algorithm?

An algorithm is a finite list of instructions that, when executed, transform a set of inputs into a desired output through a sequence of well-defined steps.

  • Example: Calculating the number of stamps needed for a letter: 1 stamp for every 5 sheets of paper.

Algorithm Example: Stamps Problem

  • Input: Number of sheets of paper.

  • Processing: Divide the number of sheets by 5 and round up to the nearest whole number.

  • Output: Number of stamps required.

  • Example Calculation: For 16 sheets: , rounded up to 4 stamps.

Formal Methods for Writing Algorithms

Common Methods

  • Flowcharts: Graphical representations of the logical steps in an algorithm, using standardized symbols.

  • Pseudocode: Plain English descriptions of algorithm steps, resembling programming language structure but not bound by syntax rules.

  • Hierarchy Charts: Diagrams showing the overall structure of a program and its modules.

Flowchart Symbols

Symbol Name

Meaning

Flowline

Shows the direction of process flow

Terminal

Represents the start or end of a process

Input/Output

Represents data input or output

Processing

Represents arithmetic or data manipulation operations

Decision

Represents a logical or comparison operation

Connector

Joins different flow lines

Annotation

Provides additional information about another symbol

Pseudocode

  • Uses English-like statements to describe algorithm steps.

  • Helps programmers focus on problem-solving logic before coding.

  • Often resembles the structure of the target programming language (e.g., Python).

Hierarchy Charts

  • Show the breakdown of a program into modules and submodules.

  • Useful for planning and organizing large programs (divide-and-conquer approach).

Programming Structures

Sequence Structure

A sequence structure consists of instructions executed one after another, without skipping or repeating any steps.

  • Example: The postage-stamp problem is solved using a sequence of input, processing, and output steps.

Decision Structure

A decision structure (or selection structure) allows a program to choose between two or more paths based on a condition.

  • If a condition is true, one set of instructions is executed; if false, another set is executed.

  • Example: Determining the direction of a numbered street in New York City: even-numbered streets are eastbound, odd-numbered are westbound.

  • Pseudocode Example:

Get street_number if street_number is even: Display 'Eastbound' else: Display 'Westbound'

Repetition Structure (Loop)

A repetition structure (or loop) executes a set of instructions multiple times, controlled by a condition.

  • Loops require an exit condition to prevent infinite repetition.

  • Example: Calculating the average grade for a class by repeatedly reading and summing grades.

Example: Class Average Algorithm

  • Input: Student grades.

  • Processing: Sum all grades, count the number of students, and calculate the average.

  • Output: Average grade.

  • Formula:

Set Counter and Sum to 0 while there are more data: Get the next Grade Increment the Counter Add the Grade to the Sum Average = Sum / Counter Display Average

Summary of Algorithm Representation Methods

  • Flowcharts: Visual, good for illustrating logic, but can become unwieldy for large programs.

  • Pseudocode: Compact, easy to modify, and closely resembles actual code.

  • Hierarchy Charts: Useful for planning program structure and organization.

Additional info: Python keywords such as if, else, and while are often used in pseudocode to clarify logic and structure.

Pearson Logo

Study Prep