The Introduction To Computer Science
The Introduction To Computer Science
Instructor:
Dr. Quincy Wu ([email protected])
Textbook:
John M. Zelle, "Python Programming: An Introduction to
Computer Science", Franklin Beedle & Associates Inc.; 3rd
Edition (Aug 2016). ISBN: 978-1-59028-2-755.
Evaluation:
Quiz (0%)
Exercise & Homework (60%)
Midterm Exam (20%)
Final Exam (20%)
Three-hour class
You are encouraged
to raise questions.
After a class
Homework
Chapter 1
Computers and Programs
Keyboard Monitor
Mouse Printer
Microphone Speaker
http://en.wikipedia.org/wiki/Von_Neumann_architecture
Python Programming, 2/e 8
The Universal Machine
What is a computer program?
A detailed, step-by-step set of instructions
telling a computer what to do.
If we change the program, the computer
performs a different set of actions or a
different task.
The machine stays the same, but the
program changes!
Source
Code
(Program) Computer
Running
an Outputs
Interpreter
Inputs
>>>
>>>
The first line tells Python we are defining a
new function called hello.
The following lines are indented to show that
they are part of the hello function.
The blank line (hit <Enter> twice) lets
Python know the definition is finished.
Python Programming, 2/e 36
The Magic of Python
>>> def hello():
print("Hello")
print("Computers are Fun")
>>>
Notice that nothing has happened yet! We’ve
defined the function, but we haven’t told
Python to perform the function!
A function is invoked by typing its name.
>>> hello()
Hello
Computers are Fun
>>>
>>>
def main():
print("This program illustrates a chaotic function")
x = eval(input("Enter a number between 0 and 1: "))
for i in range(10):
x = 3.9 * x * (1 - x)
print(x)
main()
x is an example of a variable
A variable is used to assign a name to a
value so that we can refer to it later.
The quoted information is displayed,
and the number typed in response is
stored in x.
These are
x = 3.9 * x * (1 - x)
print(x)
x = 3.9 * x * (1 - x)
equivalent! print(x)
x = 3.9 * x * (1 - x)
print(x)
x = 3.9 * x * (1 - x)
print(x)
x = 3.9 * x * (1 - x)
print(x)
x = 3.9 * x * (1 - x)
print(x)