0% found this document useful (0 votes)
12 views35 pages

Week1 Introduction

This document serves as an introduction to programming languages, specifically Python, covering fundamental concepts such as programming definitions, program design steps, flowcharts, and variable naming rules. It also discusses major computer components, data storage, programming languages, compilers, interpreters, and how to install and run Python and Anaconda. The document emphasizes good coding practices, including the use of comments for clarity.

Uploaded by

Muhammad Hamad
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views35 pages

Week1 Introduction

This document serves as an introduction to programming languages, specifically Python, covering fundamental concepts such as programming definitions, program design steps, flowcharts, and variable naming rules. It also discusses major computer components, data storage, programming languages, compilers, interpreters, and how to install and run Python and Anaconda. The document emphasizes good coding practices, including the use of comments for clarity.

Uploaded by

Muhammad Hamad
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

WEEK 1: INTRODUCTION

INS 107E Introduction to Programming Languages (Python)


This semester
Grading and Attendance Policy
Topics
What is programming?
• Computer Programming is the art of making a computer do what you want it to do.
• It consists of issuing a sequence of commands to a computer to achieve an objective
• A program (or software) is a set of instructions (commands) that a computer follows to perform a task
• Hardwares are the physical devices that make up a computer
• Computer is a system composed of several components that all work together
Steps of program design
• Program design is a must before they are written
• Typical steps of programming:
• Design the program
• Write the code
• Correct syntax errors
• Test the program
• Correct logic errors
Flowcharts
• Flowchart: diagram that graphically depicts the steps in
a program
• Ovals are terminal symbols
• Parallelograms are input and output symbols
• Rectangles are processing symbols
• Symbols are connected by arrows that represent the flow
of the program
• Statements in a program execute in the order that they
appear (from top to bottom)
Some common terms
• Function: piece of prewritten code that performs an operation
• Argument: data given to a function (i.e. data that is printed to screen
• String: sequence of characters that is used as data
• Variable: name that represents a value stored in the computer memory (a variable references the value it
represents)
• Assignment statement: used to create a variable and make it reference data (i.e. age = 29)
• Math operator: tool for performing calculation
• Operands: values surrounding the operator
• Comments: notes of explanation within a program
Variable Naming Rules
• Rules for naming variables in Python:
• Variable name cannot be a Python key word
• Variable name cannot contain spaces
• First character must be a letter or an underscore
• After first character may use letters, digits, or underscores
• Variable names are case sensitive

• Variable name should reflect its use


Major components of a computer
•Typical major components:
➢Central processing unit:
➢the part of the computer that actually runs programs
➢Main memory:
➢where computer stores a program while program is running, and
data used by the program
➢Known as Random Access Memory (RAM)
➢CPU can quickly access data in RAM
➢All gone when computer is turned off
Major components of a computer
• Typical major components:
➢Secondary storage devices:
➢can hold data for long periods of time
➢Programs are normally stored here and loaded to main memory when needed
➢Types: Disk drive, solid state drive, flash memory, optical devices
➢Input and output devices:
➢Input: the data computer collects from people and other devices
➢Input device: the component that collects the data (i.e. keyboard, mouse,
scanner, camera)
➢Output: data produced by the computer for other people or devices (can be
text, image, audio, or bit stream)
➢Output device: formats and prints the output (i.e. display, printer, speakers, disk
drive)
How the data is stored?
• All data in a computer is stored in sequences of 0s
and 1s
• Byte: just enough memory to store a letter or small
number
• Divided into eight bits
• A bit is an electrical component that can hold positive
or negative charge like an on/off switch (0 or 1)
• The on/off pattern of bits in a byte represents the data
stored

• Binary numbering system is used: 2j-1


• Byte size limits are 0 and 255
Low and High-Level Languages
• Low-level language: close to machine language
(i.e. assembly language), mnemonics that
directly correspond to machine language
instructions are used
• High-level language: symbolic languages that
use English words and/or mathematical symbols
(i.e. Python, Fortran, Basic)
• Differences in terms of ease of learning and
writing, running speed
[Link]
Compilers and Interpreters
• Programs written in high-level languages must be translated into machine language to be executed
• Compiler translates high-level language program into a separate machine language program
• Interpreter translates and executes instructions in a high-level language program
• Interprets one instruction at a time
• No separate machine language program

• Syntax error: prevents code from being translated


Compilers and Interpreters
Python Interpreter
• When you install Python you also install the Python interpreter

• Python interpreter can be used in two modes:


• Interactive mode: enter statements on keyboard
• Script mode: save statements as a Python script and then run

• Interactive mode
• Interpreter is waiting for a Python statement to be typed
• Statements are not saved as a program

• Script mode
• A set of Python statements are saved in a file named with a .py
extension
• To run the file type python [Link] at the
operating system command line
How to install Python?
• Go to [Link]
How to install Python?
• Choose your platform under the Downloads menu, download (about 30 MB, and install (typical next-
next installation)
How to install Python?
• Choose your platform under the Downloads menu, download (about 30 MB, and install (typical next-
next installation)
How to install Python?
• Choose your platform under the Downloads menu, download (about 30 MB, and install (typical next-
next installation)
How to install Python?
• Choose your platform under the Downloads menu, download (about 30 MB, and install (typical next-
next installation)
How to run Python?
• Type python in search tab of your Windows desktop, click on he Python icon that appears
How to run Python?
• Yes. That black window is your Python screen.
Good habits as we begin
• Comments in your code help you or someone else understand
• What your program does
• What a particular line or section of code does
• Why you chose to do something a particular way
• Anything that might be helpful to know if I am looking at the code later and trying to understand it!

In Python we use a # to indicate comments


#My first Python Application
#Created by me!
#Print command displays a message on the screen
print('Hello World')
Just a basic statement for displaying text
print('You can use single quotes!')

print("Double quotes is also fine!")

You can use multiple print statements


print('Print statement 1')
print('Print statement 2')

You can also use “\n” to force a new line

print('This is line 1 1\n This is line 2')


Just a basic statement for displaying text
Or you can use triple quotes:
print("""This is line 1
This is line 2 """)
Just a basic statement for displaying text

Or you can use triple quotes:


print("""This is line 1
This is line 2 """)
Is that all?

The open source Anaconda


Distribution is the easiest way to do
Python data science and machine
learning. It includes hundreds of
popular data science packages and
the conda package and virtual
environment manager for Windows,
Linux, and MacOS.

Conda makes it quick and easy to


install, run, and upgrade complex data
science and machine learning
environments like scikit-learn,
TensorFlow, and SciPy.
How to install ANACONDA?
• Go to [Link] and download the installer
How to install ANACONDA?
• Download the version compatible with your operating system (about 500 MB)
How to install ANACONDA?
• Double click to the downloaded file and install it
ANACONDA Navigator
Matplotlib

Python Core ≡ MATLAB


Numpy SciPy

You might also like