Pythonlearn 01 Intro
Pythonlearn 01 Intro
1 2
Programmers Anticipate
Users vs. Programmers
Needs
• iPhone applications are a market
• Users see computers as a set of tools - word processor, spreadsheet, map,
to-do list, etc.
• iPhone applications have over 3 billion
downloads
• Programmers learn the computer “ways” and the computer language
• Programmers have left their jobs to be
• Programmers have some tools that allow them to build new tools
full-time iPhone developers Pick Pick Pick
Me! Me! Me! • Programmers sometimes write tools for lots of users and sometimes
• Programmers know the ways of the
programmers write little “helpers” for themselves to automate a task
program Pick Pick Pay
Me! Me! Me!
3 4
10/01/21
• To get some task done - we are the user and programmer Computer
Programmer
- Clean up survey data Hardware + Software
5 6
https://www.youtube.com/watch?v=XiBYM6g8Tck
7 8
10/01/21
9 10
11 12
10/01/21
bigcount = None
bigword = None
for word,count in counts.items(): python words.py
if bigcount is None or count > bigcount: Enter file: clown.txt
bigword = word the 7
bigcount = count
Image: https://www.flickr.com/photos/allan_harris/4908070612/ Attribution-NoDerivs 2.0 Generic (CC BY-ND 2.0) print(bigword, bigcount)
13 14
Hardware Architecture
http://upload.wikimedia.org/wikipedia/commons/3/3d/RaspberryPi.jpg
15 16
10/01/21
Software What
Next?
Generic
Computer
Definitions
Input Central • Central Processing Unit: Runs the Program - The CPU is What
and Output Processing always wondering “what to do next”. Not the brains Next?
Devices Unit exactly - very dumb but very very fast
Secondary • Input Devices: Keyboard, Mouse, Touch Screen
Memory
• Output Devices: Screen, Speakers, Printer, DVD Burner
Main • Main Memory: Fast small temporary storage - lost on reboot - aka RAM
Memory
• Secondary Memory: Slower large permanent storage - lasts until deleted - disk
drive / memory stick
17 18
Generic Generic
Software What Software What
Next? Computer Next? Computer
Input Central Input Central
and Output Processing and Output Processing
Devices Unit Devices Unit
Secondary 01001001 Secondary
if x< 3: print Memory 00111001 Memory
Main Main
Memory Memory
Machine
Language
19 20
10/01/21
What
Next?
http://www.youtube.com/watch?v=9eMWG3fwiEU
http://www.youtube.com/watch?v=y39D4529FM4
21 22
http://harrypotter.wikia.com/wiki/Parseltongue
23 24
10/01/21
• You must remember that you are intelligent and can learn. The computer is
simple and very fast, but cannot learn. So it is easier for you to learn Python than
for the computer to learn English...
25 26
csev$ python3
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwinType
"help", "copyright", "credits" or "license" for more information.
Talking to Python >>>
What
next?
27 28
10/01/21
csev$ python3
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwinType
"help", "copyright", "credits" or "license" for more information.
>>> x = 1
>>> print(x)
What Do We Say?
1
>>> x = x + 1 This is a good test to make sure that you have
>>> print(x) Python correctly installed. Note that quit() also
2 works to end the interactive session.
>>> exit()
29 30
print(bigword, bigcount)
31 32
10/01/21
33 34
Python Scripts
• Interactive Python is good for experiments and programs of 3-4 lines
long.
Programming Paragraphs • Most programs are much longer, so we type them into a file and tell
Python to run the commands in the file.
35 36
10/01/21
37 38
39 40
10/01/21
Repeated Steps
name = input('Enter file:')
handle = open(name, 'r') Sequential
n=5
Repeated
counts = dict()
No Yes Output: for line in handle: Conditional
n>0? Program: words = line.split()
5 for word in words:
print(n) counts[word] = counts.get(word,0) + 1
n = 5 4
while n > 0 :
print(n)
3 bigcount = None
n = n -1 n = n – 1 2 bigword = None
print('Blastoff!') 1 for word,count in counts.items():
if bigcount is None or count > bigcount:
Blastoff! bigword = word
bigcount = count
Loops (repeated steps) have iteration variables that
print('Blastoff')
change each time through a loop. print(bigword, bigcount)
41 42
Summary
name = input('Enter file:') A short Python “Story”
handle = open(name, 'r') about how to count
counts = dict()
words in a file
for line in handle:
words = line.split() A word used to read
for word in words:
counts[word] = counts.get(word,0) + 1
data from a user • This is a quick overview of Chapter 1
bigcount = None A sentence about • We will revisit these concepts throughout the course
bigword = None
for word,count in counts.items():
updating one of the
many counts • Focus on the big picture
if bigcount is None or count > bigcount:
bigword = word
bigcount = count A paragraph about how
to find the largest item
print(bigword, bigcount) in a list
43 44
10/01/21
Acknowledgements / Contributions
These slides are Copyright 2010- Charles R. Severance
Continue…
(www.dr-chuck.com) of the University of Michigan School of
Information and made available under a Creative Commons
Attribution 4.0 License. Please maintain this last slide in all
copies of the document to comply with the attribution
requirements of the license. If you make a change, feel free to
add your name and organization to the list of contributors on this
page as you republish the materials.
45