Introduction to Programming CCC101 Computer Programming 1 In this module, you will learn about: • the fundamentals of computer programming, i.e., how the computer works, how the program is executed, how the programming language is defined and constructed; • the difference between compilation and interpretation; • what Python is, how it is positioned among other programming languages, and what distinguishes the different versions of Python. How does a computer program work? • A program makes a computer usable. • Contemporary computers excel at executing fundamental operations rapidly and repeatedly. How does a computer program work? • Example: Calculating average speed during a journey. • It is necessary to instruct the computer to: 1. accept a number representing the distance; 2. a number representing the travel time; 3. divide the former value by the latter and store the result in the memory; 4. display the result (representing the average speed) in a readable format. • These steps collectively create a program. • Translation into a language computers understand. Natural languages vs. programming languages • A language is a means (and a tool) for expressing and recording thoughts. • Computers have their own language, too, called machine language, which is very rudimentary. • A complete set of known commands is called an instruction list (or IL) What makes a language? •Languages, whether machine or natural, encompass key elements: ▪Alphabet: Set of symbols forming words. ▪Lexis (Dictionary): Collection of words. ▪Syntax: Rules to create valid sentences. ▪Semantics: Rules for meaningful phrases. Machine language vs. high-level language •Machine Language ▪IL: The alphabet of machine language. ▪Basic symbols to command computers. ▪Simplest form of communication with computers. Machine language vs. high-level language •High-Level Programming Languages: ▪Complex enough for humans, simpler than natural language. ▪Use of symbols, words, and conventions readable to humans. Machine language vs. high-level language •High-Level Programming Languages: ▪High-level language program: Source code. ▪Program's content stored in a source file. Compilation vs. Interpretation • Computer programming is the act of composing the selected programming language's elements in the order that will cause the desired effect. • Program needs to be translated into machine language for execution. • Computers can automate this translation process, making the whole process fast and efficient. Compilation vs. Interpretation Compilation: • Source program translated into machine code once. • Resulting file (e.g., .exe) distributed for execution. • Utilizes a compiler or translator. • Repeated compilation needed for source code modifications. Compilation vs. Interpretation Interpretation: • Source program translated each time it's run. • Program called an interpreter transforms code on the fly. • Users require the interpreter to execute the code. • Distribution of source code requires accompanying interpreter. What does the interpreter do? • After writing a program, it exists as a computer file. • A computer program is essentially a piece of text. • Invoke the interpreter to process your program. • Interpreter sequentially reads, checks, and executes code. What does the interpreter do? • Python is an interpreted language. • If you want to program in Python, you'll need the Python interpreter. You won't be able to run your code without it. Fortunately, Python is free. • Languages designed for interpretation often termed "scripting languages." • Source programs encoded using these languages referred to as "scripts." What is Python? • Widely-used, interpreted, objectoriented, high-level programming language. • comes from "Monty Python's Flying Circus”, a BBC television comedy sketch series Who created Python? • Python's uniqueness: Created by an individual. • Guido van Rossum, born 1956, Haarlem, Netherlands. • first released on February 20, 1991. • Python's global reach propelled by collective efforts. • Thousands of programmers, testers, users, enthusiasts. Why Python? Where can we see Python in action? • used extensively to implement complex Internet services like: ▪ search engines ▪ cloud storage and tools ▪ social media and so on • More and more everyday-use applications are being written in Python. • Scientists transition to Python for research and analysis Python 2 vs. Python 3 • Python 2: • Older version, development intentionally stalled. • Regular updates addressing bugs and security. • Active but not evolving language. • Python 3: • Current version, actively evolving. • Creating new standards and conventions. • Independent language evolution. Getting Started with Python • Linux Users Most Linux distributions come with Python pre-installed due to its integral role in the system. Check Python Installation: Open the terminal/console and type: Press Enter and wait for the Python prompt. Getting Started with Python • Linux Users Getting Started with Python • If Python 3 is absent, refer to your Linux documentation to use your package manager for installation: • All non-Linux users can download a copy at https://www.python.org/downloads/ Getting Started with Python 1. Visit the Python Download Page • Open your web browser and go to: www.python.org/downloads Getting Started with Python 2. Choose Your Python Version • Since the website detects your OS, click on the Python 3 version offered. This will be the latest release 3. For Windows Users • Download the .exe file. • Run the downloaded file. • Follow the installation steps. • Important: Check the "Add Python 3.x to PATH" checkbox. • Leave other settings as default for now. Getting Started with Python 4. For macOS Users • Python 2 might be preinstalled, but we'll work with Python 3. • Download the relevant .pkg file from the Python site. • Run the downloaded .pkg file. • Follow the installation instructions. Starting your work with Python To start your work, you need the following tools: • Code Editor: support you in writing the code • Console: Launch and control your code's execution. • Debugger: Step-by-step code execution for thorough inspection. Starting your work with Python • Python 3 standard installation contains a very simple but extremely useful application named IDLE (Integrated Development and Learning Environment)