Introduction to Computing, Problem Solving, and Program Design
Introduction to Computing and Problem Solving
- General Overview: This course module serves as an introduction to basic methodology for solving problems using computer programs, specifically focusing on program design and the Python programming language.
- Preparation Credits: Prepared by Suhaini Nordin, with specific acknowledgments to Ban Kar Weng (William) for original pedagogical materials.
Questions & Discussion
- How do we communicate with the computer?: Through the use of programming languages.
- How do we get computers to perform complicated tasks?: These tasks are broken down systematically into a sequence of small, manageable instructions.
- Why Python?: Python is popular because it is powerful, easy to download, easy to write, and easy to read.
- How did the language Python get its name?: It was named after the British comedy group "Monty Python."
- What is IDLE?: IDLE stands for Integrated DeveLopment Environment. It includes the Python Shell and a text editor used by programmers to write and execute scripts.
- What is an interpreted language?: A language that utilizes an interpreter, which translates high-level code into machine language one statement at a time and executes it immediately.
- What are the meanings of the terms "programmer" and "user"?:
- Programmer: A person who identifies problems and solves them by writing instructions for a computer.
- User: Any individual who runs or interacts with a program created by a programmer.
- What is the meaning of the term "code"?: Code refers to the specific Python statements written by the programmer to perform logic.
- Are there certain characteristics that all programs have in common?: Yes, they all follow the fundamental sequence of Input, Processing, and Output (IPO).
- What are the meanings of the terms "hardware" and "software"?:
- Hardware: The physical, tangible components of the computer system.
- Software: The digital instructions or program that runs on the hardware.
- How are problems solved with a program?: By devising a step-by-step procedure designed to process data inputs and produce the desired output.
- What is a zero-based numbering system?: A system where the counting or indexing sequence begins with the digit rather than .
- What are the prerequisites to learning Python?: Students should be familiar with computer file and folder management (operating system basics).
Program Development Cycle
The problem-solving process typically flows through three stages:
- Input: Receiving data into the system.
- Processing: Executing logic or calculations on the input data.
- Output: Displaying the results of the processing.
Detailed Program Planning Stages:
- Analyze: Define the problem clearly. This involves asking questions and checking for all possible edge cases or scenarios.
- Design: Plan the solution strategy. This involves writing pseudocode or drawing a flowchart to visualize logic before writing code.
- Code: Translate the planned algorithm into a specific programming language (e.g., Python).
- Test, Debug, and Correct: Locate, isolate, and remove errors (bugs) within the program to ensure it functions as intended.
- Complete Documentation: Organize all materials, descriptions, and logic summaries that explain how the program works for future users or developers.
Program Design vs. Coding Example
- Scenario: Checking if a provided number is positive, negative, or zero.
- Solution Logic:
- Ask the user to provide a number.
- If the number is , it is identified as "zero."
- If the number is greater than , it is identified as a "positive number."
- If the number is less than , it is identified as a "negative number."
- Design Steps:
- Get number.
- If number then print "Zero".
- If number then print "Positive number".
- If number then print "Negative number".
Problem-Solving Skill Test: Jack's Path
- Objective: Guide a character named "Jack" from a starting point to a destination using only simple commands: Move forward, Turn left, Turn right, and Stop.
- Logic Steps:
- Move forward steps.
- Turn right.
- Move forward steps.
- Turn left.
- Move forward steps.
- Turn right.
- Move forward steps.
- Turn right.
- Move forward steps.
- Stop.
Programming Tools: Definitions and Symbols
Algorithm: A step-by-step procedure for solving a problem.
Pseudocode: An abbreviated version of actual computer code written in plain English. It replaces flowchart symbols with English-like statements, allowing the programmer to focus on logic rather than syntax.
Flowchart: A visual representation of an algorithm using standard symbols.
Flowchart Symbols:
- Flowline: Represented by an arrow; indicates the direction of logic flow.
- Terminal: Represented by a rounded rectangle (oval); indicates the Start or End of a program.
- Input/Output: Represented by a parallelogram; used for reading input from the user or displaying output results.
- Processing: Represented by a rectangle; used for calculations or data manipulation.
- Decision: Represented by a diamond; used for branching logic (Yes/No or True/False conditions).
- Connector: Represented by a small circle; used to connect different parts of a flowchart across pages or sections.
- Annotation: Used for adding descriptive notes or comments within the flowchart.
Case Study: The Postage-Stamp Problem
- Problem: Determine the number of stamps needed for a letter.
- Rule of Thumb: Provide stamp for every sheets of paper.
- Algorithm steps:
- Get the total sheets of paper.
- Divide the number of sheets by .
- Round the quotient up to the next whole number; store this as the number of stamps.
- Display final stamp count.
- Processing breakdown for 16 sheets:
- Input:
- Processing:
- Process (Rounding): Rounding up gives .
- Output:
- Pseudocode:
- Read Sheets
- Set stamps = Sheets /
- Round stamps up to the next whole number
- Display stamps
Case Study: New York City Street Directions
- Objective: Determine if a one-way street in NYC runs Eastbound or Westbound based on the street number.
- Rule: Even-numbered streets run Eastbound; odd-numbered streets run Westbound.
- IPO Breakdown:
- Input: Street number ().
- Processing: Check if is divisible by (i.e., check if ).
- Output: "Eastbound" if even, "Westbound" if odd.
- Pseudocode:
- Get street
- if street is even
- Display Eastbound
- else
- Display Westbound
Case Study: Class Average Calculation
- Objective: Calculate and report the average grade for a class.
- Logic Required:
- A loop is needed to read grades and accumulate a sum.
- A counter is needed to track the number of students.
- IPO Breakdown:
- Input: Student grades.
- Processing:
- Initialize and .
- While data exists: Add grade to Sum, add to Counter.
- Output: Average grade.
- Pseudocode:
- Initialize Counter and Sum to
- while there are more data
- Get the next Grade
- Increment the Counter
- Add the Grade to the Sum
- Compute Average = Sum / Counter
- Display Average
The Python Language
- History: Conceived by Guido van Rossum in the 1980s. Its name originates from the "Monty Python’s Flying Circus" comedy sketch show.
- Growth Drivers:
- Simplicity and development speed.
- Significant adoption by the Data Science and Machine Learning communities.
- Availability of extensive libraries that extend core functionality.
- Industry Use: Major companies using Python include Spotify, Facebook, Amazon, Google, and YouTube.
- Example Code (Factorial Calculation):
- File:
factorial.py - Logic:
- Console Result: If input is , output is .
- File:
Language Translators
- Translator: A tool that translates high-level programming language (Basic, C++, Java, Python, etc.) into machine language ( and ) so the computer can execute it.
- Types of Translators:
- Interpreter:
- Reads code, parses it, and executes instructions "on the fly."
- Examples: Python, JavaScript, PHP.
- Compiler:
- Translates the entire source program into machine language at once.
- Saves the translation into a file (e.g.,
.exeor.dll) for subsequent execution. - Examples: C, C++.
- Interpreter:
Educational Tools for Programming
- Blockly Games: A Google-supported visual programming tool (block-based) for learning logic (Puzzle, Maze, Logic, Loops, Math).
- Lightbot: A game-based platform designed to teach sequencing, procedures, and loops visually without writing syntax.
- Evolution of Languages: Mentions the shift from older languages (COBOL) to modern, widely accessible languages like Swift, Kotlin, Dart, and Python.