Topic_1__-_Introduction

Introduction to CSPG1205 Programming Python

  • Outcome #1: Define computer programming concepts.

What is a Computer Program?

  • A program is a sequence of instructions specifying how to perform a computation.

  • Computations can be categorized into:

    • Mathematical: Solving equations.

    • Symbolic: Searching/replacing text in a document.

    • Graphical: Processing images or videos, and more.

Why Should You Learn to Write Programs?

  • Problem solving is crucial for computer scientists:

    • It involves formulating problems, thinking creatively about solutions, and expressing these solutions clearly.

    • Learning to write computer programs provides an excellent opportunity to practice these skills.

  • Example Problem: To find speed during a journey:

    • Know distance.

    • Know time.

    • Divide distance by time to find speed.

    • Display the speed result.

Languages

  • Definition: A language is a tool to express and record thoughts.

  • Machine Language: The computer's own language.

  • Natural Language: Human languages; a common language for humans and computers is necessary.

Programming Languages

  • A programming language is a formal language used to create computer programs.

  • Examples of programming languages:

    • Python

    • C++

    • JavaScript

    • Scala

    • Java

    • PHP

    • Ruby

    • C#

Programmer

  • A programmer is someone skilled in programming.

  • Responsibilities include:

    • Writing source code for applications.

    • Testing, maintaining, and debugging software applications.

Building Blocks of Programs

  • Input: Acquiring data from external sources (keyboard, files, sensors).

  • Output: Displaying results or storing them (e.g., on a screen or in a file).

  • Execution Types:

    • Sequential execution: Running statements one after another.

    • Conditional execution: Executing or skipping statements based on certain conditions.

    • Repeated execution: Running a set of statements multiple times, with variations.

    • Reuse: Creating named instructions for recurring use throughout the program.

About Python

  • General Characteristics:

    • Easy to learn.

    • Widely used in various organizations (e.g., Google, NASA, Yahoo).

    • Created by Guido van Rossum in 1991.

    • Named after “Monty Python’s Flying Circus.”

Companies Using Python

  • Notable companies include:

    • Nokia

    • Amazon

    • Dropbox

    • Reddit

    • Yahoo!

    • IBM

    • Quora

    • Disney

    • Netflix

Advantages of Python

  • Simplicity and Power:

    • Efficient high-level data structures.

    • Object-oriented programming capabilities.

  • Characteristics:

    • Interpreted language with dynamic semantics.

    • High-level language: No need to manage memory.

    • Portable across platforms without changes.

Features of Python

  • Simple and Minimalistic Language:

    • Easy to learn and has an intuitive syntax.

  • Free and Open Source:

    • Can be freely distributed and modified.

  • Interpreted Language:

    • Runs programs directly from source code by converting into bytecodes and then running on the native mode.

  • Object-Oriented:

    • Supports both procedural and object-oriented programming, enabling code reuse and reducing complexity.

Object-Oriented vs. Procedure-Oriented Programming

  • Procedure-Oriented Language:

    • Centers around procedures or functions, executing commands in a specific order, facilitating code reuse.

  • Object-Oriented Language:

    • Focuses on objects combining data and functionalities, reflecting real-world interactions.

Extensibility and Embedding

  • Extensible:

    • Critical pieces of code can be written in fast languages (e.g., C/C++) and called from Python.

  • Embedded:

    • Python can be integrated within C/C++ programs for scripting capabilities.

Extensive Libraries

  • Python has a vast Standard Library assisting with:

    • Regular expressions, multi-threading, databases, web browsers, HTML, GUI development, etc.

Interpreter and Compiler

  • Machine Language:

    • Comprised of zeros and ones (binary), specific to hardware and not portable.

  • High-Level Language:

    • Python is user-friendly for reading and writing, contrasting with machine language.

  • Types of Translators:

    • Interpreters: Read source code and execute on the fly.

    • Compilers: Convert entire source code to machine language at once.

Terminology: Interpreter vs. Compiler

  • Interpreter:

    • Processes Python code instantly, allowing immediate response in an interactive setting.

  • Compiler:

    • Translates source code into machine language, creating files for later execution.

Example: Hello World Program in Python

  • Written in three lines:

    • Line 1: Comment indicating program start (#).

    • Line 2: print(“Hello world!”) function to output text.

    • Line 3: Comment indicating program end (#).

Python Programming Environment: Jupyter Notebooks

  • Features:

    • Enables creation and execution of interactive programs in a single document.

    • Accessible through a web browser with features for direct sharing and visualization.

Anaconda Navigator

  • Applications:

    • Includes Jupyter Notebook, JupyterLab, Spyder (IDE) for Python development.

Working with Jupyter Notebooks

  • Creating a New Notebook:

    • Accessible via the 'New' button in the Jupyter interface for Python 3.

Notebook Structure and Cells

  • Notebook Cells:

    • Comprised of various cell types:

      • Code Cell: Contains executable code.

      • Markdown Cell: Contains formatted text.

      • Raw Cell: Displays content without processing.

Notebook Tips

  • To execute cells:

    • Select and press shift + enter or ctrl + enter.

    • Options to run all cells or specific ones.

    • Features for adding, deleting, and reordering cells.

    • Supports saving and downloading in various formats (.ipynb, .py, .pdf, .html).

References

  • Learning resources:

    • Severance C. R. (2016). Python for Everybody.

    • Swaroop C.H. (2013). A Byte of Python.

    • Downey A.B. (2016). Think Python.

    • Romano F. (2018). Learn Python Programming.

robot