Week 1
Week 1
2
How do people use a computer?
3
Programmers Anticipate Needs
https://www.youtube.com/watch?v=vlzwuFkn88U
Programs for Humans
While music is playing:
Central
Input and Output
Processing
Devices
Unit
Secondary
Memory
Main
Memory
Definition of hardware
Central
Input and Output
Processing
Devices
Unit
Secondary
if x< 3:
Memory
print
Main
Memory
What Generic Computer
Software Next?
Central
Input and Output
Processing
Devices
Unit
Secondary
01001001
00111001 Memory
Main
Memory
Machine Language
Secondary storage devices
http://www.youtube.com/watch?v=9eMWG3fwiEU
1
Definition of software
-Software that serves to help “users more productive and/or assist them
with personal tasks” (Shelly, Cashman & Vermaat)
-There are two general categories of software: system software and
application software
• System software typically includes Operating Systems and Utility
Programs
• Application Software is described as a set of programs that are
designed to perform specific tasks for the user
1
Definition of software
User
Programmer
Computer....
Hardware + Software
- We figure something out and then we encode it and then give it to someone else to
save them the time and energy of figuring it out
- It's extensive libraries and active community support further enhance its appeal.
18
Why do people use Python?
Multi-Paradigm
Dynamically
Typed
Open Source
Large Standard
Library Interpreted
Easy and
Diversified
simple
19
Python can be used in almost all disciplines:
• Web Development
• Data Analysis Large Standard Library
• Machine Learning Python contains thousands of
• Testing popular external libraries like:
• Big Data Numpy, Pandas, Scipy,
Tensorflow etc..
• Android App Development
• Web Scraping
20
Easy and Simple
20
21
Talking to Python
22
What next?
23
This is a good test to make sure that you have
Python correctly installed. Note that quit() also
works to end the interactive session.
24
What Do We Say?
25
Elements of Python
- Input, Processing, and Output (Chapter 2)
- Functions (Chapter 5)
- Strings (Chapter 6)
counts = dict()
A short “story” about how to
for line in handle:
words = line.split() count words in a file in Python
for word in words:
counts[word] = counts.get(word,0) + 1
print(bigword, bigcount)
27
Reserved Words
28
Sentences or Lines
x = 2 Assignment statement
x = x + 2 Assignment with expression
print(x) Print statement
29
Programming Paragraphs
30
Python Scripts
-Interactive Python is good for experiments and programs of 3-4 lines
long.
-Most programs are much longer, so we type them into a file and tell
Python to run the commands in the file.
-As a convention, we add “.py” as the suffix on the end of these files to
indicate they contain Python.
31
Interactive versus Script
• Interactive
• Script
- You enter a sequence of statements (lines) into a file using a text editor and
tell Python to execute the statements in the file
32
Program Steps or Program Flow
- Sometimes we store a set of steps to be used over and over as needed several
places throughout the program (Chapter 4).
33
Sequential Steps
x=2 Program:
Output:
print(x) x = 2
print(x) 2
x=x+2 x = x + 2 4
print(x)
print(x)
print('Smaller') Program:
No Output:
x = 5
Yes if x < 10: Smaller
x > 20 ? print('Smaller') Finish
if x > 20:
print('Bigger')
No print('Bigger')
print('Finish')
print('Finish')
35
n=5 Repeated Steps
No Yes Output:
n>0? Program:
5
print(n) n = 5 4
while n > 0 :
print(n)
3
n = n -1 n = n – 1 2
print('Blastoff!') 1
Blastoff!
Loops (repeated steps) have iteration variables that
print('Blastoff')
change each time through a loop.
36
name = input('Enter file:') Sequential
handle = open(name, 'r')
Repeated
counts = dict()
Conditional
for line in handle:
words = line.split()
for word in words:
counts[word] = counts.get(word,0) + 1
bigcount = None
bigword = None
for word,count in counts.items():
if bigcount is None or count > bigcount:
bigword = word
bigcount = count
print(bigword, bigcount)
37
name = input('Enter file:') A short Python “Story”
handle = open(name, 'r') about how to count
words in a file
counts = dict()
for line in handle:
words = line.split() A word used to read
for word in words: data from a user
counts[word] = counts.get(word,0) + 1
38
Install Python
39
The Python Interpreter
Step 1: You can download the latest version of Python from www.python.org/downloads/
40
The Python Interpreter
Step 2: You execute the file “Python-3.11.5” and choose “Run” for running the file
41
Video: Install Python (others)
• Link: https://drive.google.com/drive/folders/1icBz7aZZf7lgWZ5T9dEMZss4AGg0dhbR
42
QUIZZES
Link:https://play.kahoot.it/v2/?quizId=f2ab022d-a4ad-
489d-ac11-b13db7cfbf38
43
EXERCISES
44
EXERCISES
1. Writing Python statements is called _______________.
a. Coding
b. Compiling
c. Interpreting
d. Processing
46