Download Introduction to Programming in Python

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Abstraction (computer science) wikipedia , lookup

Stream processing wikipedia , lookup

Computer cluster wikipedia , lookup

Parallel computing wikipedia , lookup

ILLIAC IV wikipedia , lookup

Transcript
Computers and Programming
CIS 40 – Introduction to Programming in Python
De Anza College
Clare Nguyen
Intro
• Welcome to Introduction to Programming in Python.
• This course is an introductory tour into the computer
programming world, where we learn to write instructions to
tell the computer to do a task for us.
• Just as we could use English when we write instructions for
someone to do work, in this class we’ll use a language called
Python to write instructions for the computer to do work.
• Along the way, we’ll get a feel for the kind of work that goes
into creating our favorite phone app, or the myPortal system to
register for class, or an online sales transaction, etc.
• In this first module, we will go over what a computer program
is, what makes up a computer, and how a computer sees the
world.
Using the Powerpoint notes
• The topics covered in class are in these Powerpoint notes. You
can consider them class notes that have been taken for you.
• It is highly recommended that you view these notes as a slide
show so that you can see the video in the notes.
• After you’ve seen the notes as a slide show, then you can study
individual slides when you take the quizzes or do the
assignments.
• Some of the notes have different fonts to highlight them. I try
to keep them to a minimum so it’s easy to remember:
– Vocabulary terms are italicized, you should know the definition of
these terms.
– Example code are in blue, they are valid Python words or code
that you could run.
– Menu selections are in grey, you should look for them when
following instructions on how to use a tool.
What Is Programming? (1 of 2)
• Programming means writing instructions to tell the computer to
do a certain task.
• Programming is a creative and rewarding activity. Programmers
enjoy solving problems and seeing tangible results.
• People write programs for many reasons, from analyzing multidimensional data sets to creating an interactive web page to
controlling machinery.
• Computers are all around us daily: laptops and cell phones are
obvious ones, but computers are also found in cars, home
appliances, and entertainment / personal devices.
• If you have ever successfully set a ringtone on your phone, or
entered an address in a GPS, or set up a game system to play,
then you’ve had your first experience in programming. You’ve
completed a sequence of steps to tell the computer to do a task.
What Is Programming? (2 of 2)
• If we were to write the instructions to show someone how to set
the ringtone on a phone, it would be similar to this:
1.
2.
3.
4.
5.
Go to the phone Settings menu
Choose the Sound menu
Choose the Ringtones menu
Select the ringtone you like
Click OK to save the ringtone that you choose
• The steps above are instructions that we give to our phone, the
computer, to perform a task. They are equivalent to a computer
program.
• When someone calls our phone, the phone (the computer)
follows our instructions and plays our chosen ringtone.
• Similar to the “programming” example above, in this class we
write instructions that tell the computer to do a specific task,
and then we run the program to see the result.
Computer Architecture (1 of 2)
• Laptops, cell phones, game systems, certain appliances… are all
considered computers. So what makes a device a computer?
• A computer has the following main components that are
connected together:
1. Central Processing Unit or CPU: the “brain” of the computer.
The CPU runs our instructions to do the task we specify.
2. Memory: stores data and instructions that the CPU uses.
3. Network: connects the computer to the internet.
4. Input / Output or IO Devices: such as keyboard, touch
screen, camera, hard drive, sensor, etc.
An input device is used to enter data into the computer,
such as a mouse being used to select a choice.
An output device receives data that are sent out from the
computer, such as a screen that displays the result.
Computer Architecture (2 of 2)
• The following diagram shows the basic hardware components
of a computer:
Central Processing Unit
(CPU)
IO Devices
Network
Memory
• We typically use an IO device such as a keyboard to enter our
instructions (or our program) into the computer.
• The computer stores our program and data in memory.
• When the program runs, the instructions in the program are
sent to the CPU, where each instruction is run or executed.
• As the instructions run, the computer may access the network
to communicate with remote servers (other computers).
• When there are output data, the data are displayed through
output devices, sent out on the network, or stored in memory.
Instruction Cycle
When our program runs, each instruction in our program goes
through the stages of an instruction cycle:
Fetch
Store
Decode
Execute
1.
2.
3.
4.
1.
2.
The instruction is fetched from memory
It is decoded into a specific CPU operation and associated data
The CPU executes or performs the operation on the data
The result of the operation is stored
The next instruction is fetched from memory
It is decoded …
The cycle continues until all instructions have run.
Program Execution
Click for a video demo of how instructions are
executed in a program
Data Representation (1 of 2)
• As the CPU runs the instructions in our program, some
instructions require input data. For example, if the task is to
calculate the tip for a restaurant bill, the required data will be
the cost of the meal and the percent of tipping rate.
• Many of the data used in a computer program are numeric
data such as a dollar amount or a percent, but some data can
be text characters, such as in this Powerpoint slide, or images,
such as the pictures we take with our phone.
• How does the computer handle different kinds of data?
The answer is that the computer doesn’t work with different
kinds of data. It only works with one kind: numbers.
• This is straightforward when the data are already numbers, but
when data are text characters or images, they are actually also
stored as numbers on the computer.
Data Representation (2 of 2)
• Text characters are translated into numbers by using the ASCII
or Unicode standards. Across computer systems, the word
“Python” is seen as the sequence: 80 121 116 104 111 110,
one number for each letter.
• Likewise, a digital image is divided into many rows and columns,
and each cell is a pixel. Each pixel is one tiny part of the image,
and the pixel’s color is stored as 3 numeric values. For example,
a dark green pixel has the values (50 100 50) and a light grey
pixel has the values (200 200 200).
• In addition, all the numeric values given above are in base 10,
which is the most familiar base for us humans. Computers work
with base 2, or binary, because at the most basic level, the
computer hardware can only detect 2 states: on or off.
Therefore, the computer actually sees the green pixel discussed
above as the sequence: 00110010 01100100 00110010
What’s Next
• At this point you may wonder if in class we’ll have to work with
numbers such as: 10101000 + 01011001
• The answer is no, fortunately. We’ll be able to work in a much
more “human” way: 168 + 89 (these base 10 values correspond
to the binary values above).
• To see why we don’t have to “speak” binary to the computer,
we’ll continue with module 2.