Professional Documents
Culture Documents
Introduction to
programming
A SHORT INTRODUCTION TO HARDWARE,
SOFTWARE, AND ALGORITHM DEVELOPMENT
Chapter 1
input output
(data) (results)
(computing /
elaboration)
Politecnico di Torino, 2021/22 COMPUTER SCIENCES 5
Problems
▪ How to encode data in a format that can be understood by the
computer
▪ How to encode the commands or instructions into a sequence of
operations that composes the desired elaboration
▪ How to codify the results in a format that can be understood by
the human user
Data
Voice
01101100
Music
Images
Videos
Politecnico di Torino, 2021/22 COMPUTER SCIENCES 7
Hardware and Software
▪ An electronic computer is composed of two parts:
o Hardware:
Physical component, consisting of electronic devices, and mechanical, magnetic and optical
parts
o Software:
“intangible” component consisting of:
• Programs: The “instructions” for hardware
• Data: Information upon which programs operate
Building
a program
4102
8745
Solution
Formal
solution
Program
Informal
▪ Solution: The maximum is the solution
larger number between A and B…
Formal
▪ Formal solution: solution
1. initially: max = 0
2. if A > B then max = A; stop
3. otherwise max = B; stop
7345 1302
5901
▪ Flow Charts
o Pros
• More intuitive: graphical formalism
• More abstract algorithm description
o Cons
• Require learning the meaning of different blocks
• Struggle to represent complex or more abstract operations
▪ Assembly Language
… Specific for a given architecture
LOAD Reg1, Mem[1000] (microprocessor)
ADD Reg1, 10
…
100
101
x; integer; 3 102
value=3
103 Memory
c; character; ‘a’ 104 addresses
value=‘a’ 105
106
t; real; 107
-11.564
value=-11.564 108
Memory
If you know how to think... then you are a free human being.
(Krishnamurti)
Sequential operations
Sub-operations
Repetitions
structure-1
structure
structure-2
T condition F
structure-1 structure-2
T condition F
structure
condition F
structure
structure
condition
T
F
Politecnico di Torino, 2021/22 COMPUTER SCIENCES 55
Conditional Flowcharts
▪ Two Outcomes ▪ Multiple Outcomes
▪ One day Fred’s boss, Joe, tells Fred that at any time during the day
he (Joe) will need to know:
o how many bunches of flowers have been sold
o what was the value of the most expensive bunch sold
o what was the value of the least expensive bunch sold
o what is the average value of bunches sold
▪ You should use the method you are most comfortable with
o In this course we will use the PyCharm IDE or the repl.it on-line IDE
o Book examples use the Wing IDE or the Spyder IDE
hello.py
• IDE
run • Console
Program output
Debugger/Output
Example main.py
(may modify or
delete)
Type program
Run
Run again
shortcut
Program output
Python console
Project files
Program output
Program source
print(3 + 4)