0% found this document useful (0 votes)
15 views

Week 1

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Week 1

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Week 1

Introduction to computers and


programming
Learning Objectives

1. Identify differences between hardware and software


2. Understand how a computer works
3. Know how data is stored and manipulated
4. Explain why programs are written in high-level languages
5. Install Python
6. Quizzes and exercises

2
How do people use a computer?

- Computers are built for one purpose - to do things for us What


Next?
- But we need to speak their language to describe what we want
done
-Users have it easy - someone already put many different
programs (instructions) into the computer and users just pick the
ones they want to use
What What What
Next? Next? Next?

What What What


Next? Next? Next?

3
Programmers Anticipate Needs

- iPhone applications are a market

- iPhone applications have over 3 billion downloads

-Programmers have left their jobs to be full- time


iPhone developers

- Programmers know the ways of the program What What What


Next? Next? Next?

What What Pay


Next? Next? me
Programs for Humans

https://www.youtube.com/watch?v=vlzwuFkn88U
Programs for Humans
While music is playing:

Left hand out and up


Right hand out and up
Flip Left hand
Flip Right hand
Left hand to right shoulder
Right hand to left shoulder
Left hand to back of head
Right ham to back of head
Left hand to right hit
Right hand to left hit
Left hand on left bottom
Right hand on right bottom
Wiggle
Wiggle https://www.youtube.com/watch?v=vlzwuFkn88U
Jump
Programs for Humans
While music is playing:

Left hand out and up


Right hand out and up
Flip Left hand
Flip Right hand
Left hand to right shoulder
Right hand to left shoulder
Left hand to back of head
Right ham to back of head
Left hand to right hit
Right hand to left hit
Left hand on left bottom
Right hand on right bottom
Wiggle
Wiggle https://www.youtube.com/watch?v=vlzwuFkn88U
Jump
Programs for Humans
While music is playing:
Left hand out and up
Right hand out and up
Flip Left hand
Flip Right hand
Left hand to right shoulder
Right hand to left shoulder
Left hand to back of head
Right ham to back of head
Left hand to right hip
Right hand to left hip
Left hand on left bottom
Right hand on right bottom
Wiggle
Wiggle
Jump
https://www.youtube.com/watch?v=XiBYM6g8Tck
What Generic Computer
Software Next?

Central
Input and Output
Processing
Devices
Unit
Secondary
Memory

Main
Memory
Definition of hardware

- Central Processing Unit: Runs the Program - The CPU is


always wondering “what to do next”. Not the brains
exactly - very dumb but very very fast

- Input Devices: Keyboard, Mouse, Touch Screen

- Output Devices: Screen, Speakers, Printer, DVD Burner

- Main Memory: Fast small temporary storage - lost on


reboot - aka RAM

- Secondary Memory: Slower large permanent storage -


lasts until deleted - disk drive/memory stick
What Generic Computer
Software Next?

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

Data Information Networks


What is Code? Software? A Program?

• A sequence of stored instructions

- It is a little piece of our intelligence in the computer

- 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

• A piece of creative art - particularly when we do a good job on user experience


High-Level Languages

A low-level language A high-level language

❖ Assembly language is a direct ❖ In the 1950s, high-level languages

substitute for machine language began to appear.

❖ Allows you to create powerful and


❖ Requires that you know a lot
complex programs without:
about the CPU
- Knowing how the CPU works
- Writing large numbers of low-level
instructions
- Using words that are easy to
understand
17
What is Python?

- Python is an interpreted, object-oriented, high-level programming language with


dynamic semantics.

- It was created by Guido van Rossum and first released in 1991[*].

- An individual who can speak Python is known as a Pythonista.


- It is a very uncommon skill, and may be hereditary
-Python's versatility and user-friendly syntax make it a popular choice among
developers for various applications, from web development to scientific computing
and machine learning.

- 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

Static Typed Languages: Dynamic Typed Languages:


Ex: int a=10; Ex: a=10;
char a='c'; (not possible) a='b’; (possible)

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)

- Decision Structures and Boolean Logic (Chapter 3)

- Repetition structures and loops (Chapter 4)

- Functions (Chapter 5)

- Strings (Chapter 6)

- Lists and Tuples (Chapter 7)

- Files and Exceptions (Chapter 8)

- Dictionaries and Sets (Chapter 9)

- Classes and Object-Oriented Programming (Chapter 10) 26


name = input('Enter file:')
handle = open(name)

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

bigcount = None python words.py


bigword = None
for word,count in counts.items(): Enter file: words.txt
if bigcount is None or count > bigcount: to 16
bigword = word
bigcount = count

print(bigword, bigcount)

27
Reserved Words

You cannot use reserved words as variable names / identifiers

False class return is finally


None if for lambda continue
True def from while nonlocal
and del global not with
as elif try or yield
assert else import pass
break except in raise

28
Sentences or Lines

x = 2 Assignment statement
x = x + 2 Assignment with expression
print(x) Print statement

Variable Operator Constant Function

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.

- In a sense, we are “giving Python a script”.

-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

- You type directly to Python one line at a time and it responds

• 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

- Like a recipe or installation instructions, a program is a sequence of steps to be


done in order.

- Some steps are conditional - they may be skipped.

- Sometimes a step or group of steps is to be repeated.

- 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)

When a program is running, it flows from one step to the next. As


programmers, we set up “paths” for the program to follow.
34
x=5
Conditional Steps
Yes
x < 10 ?

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

bigcount = None A sentence about


bigword = None updating one of the
for word,count in counts.items(): many counts
if bigcount is None or count > bigcount:
bigword = word
A paragraph about how
bigcount = count
to find the largest item
print(bigword, bigcount) in a list

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

2. Which one of the following is not a high-level language?


a. Assembly language
b. Java
c. Visual Basic
d. Python
45
EXERCISES
3. An error in a program is called a(n) _______________.
a. Bug
b. Moth
c. Incomplete input
d. Cycle

4. A sequence of instructions is called a(n) _______________ .


a. Program
b. High - level language
c. Interpreter
d. Flowchart

46

You might also like