Uploaded by Florante Vienes

Python LAB5

advertisement
PLATFORM
TECHNOLOGIES (Laboratory)
LEARNING GUIDE 2020
FLORANTE CS2
B.101
VIENES
– Basic Computer Concepts and Applications
iv
This learning module is developed for instructional
purposes only. Any form of reproduction or
distribution is strictly prohibited.
IT 203L – Platform Technologies
ii
Southern Leyte State University
Vision
A high quality corporate University of Science, Technology and Innovation.
Mission
SLSU will:
a) Develop Science, Technology, and Innovation leaders and
professionals;
b) Produce high-impact technologies from research and innovations;
c) Contribute to sustainable development through responsive
community engagement programs;
d) Generate revenues to be self-sufficient and financially-viable.
Quality Policy
We at Southern Leyte State University commit enthusiastically to satisfy our
stakeholders’ needs and expectations by adhering to good governance,
relevance and innovations of our instruction, research and development,
extension and other support services and to continually improve the
effectiveness of our Quality Management System in compliance to ethical
standards and applicable statutory, regulatory, industry and stakeholders’
requirements.
The management commits to establish, maintain and monitor our quality
management system and ensure that adequate resources are available.
IT 203L – Platform Technologies
iii
COURSE OVERVIEW
Course No.
Course Code
IT203L
Descriptive Title
Platform technologies
Credit Units
1 unit
School Year/Term
2020 – 2021 / First Semester
Mode of Delivery
Modular
Name of Instructor
Florante B. Vienes
Course Description
The course is designed to provide an introduction to the
Python programming language. The focus of the course is to
provide students with an introduction to programming, I/O,
and visualization using the Python programming language.
Course Outcomes
At the end of the course, students should be able to:
1.
2.
3.
4.
5.
Install and run the Python interpreter
Create and execute Python programs
Understand the concepts of file I/O
Be able to read data from a text file using Python
Plot data using appropriate Python visualization
libraries
IT 203L – Platform Technologies
iv
MODULE GUIDE
IT 203L – Platform Technologies
iv
TABLE OF CONTENTS
PAGE
PRELIMINARIES
Cover Page
i
Disclaimer
ii
SLSU Vision, Mission, Quality Policy
iii
Course Overview
iv
Module Guide
v
Table of Contents
vi
Laboratory
Activity
Exercises
V
1
Python Dictionaries
2
Dictionaries: Common Applications
3
Dictionaries and Loops
4
The Tuples Collection
5
Comparing and Sorting Tuples
IT 203L – Platform Technologies
Laboratory Activity 5
IN THIS ACTIVITY, YOU WILL LEARN HOW TO:
1
Python Dictionaries
2
Dictionaries: Common Applications
3
Dictionaries and Loops
4
The Tuples Collection
5
Comparing and Sorting Tuples
IT 203L – Platform Technologies
Python for Everybody - Python Dictionaries
https://www.freecodecamp.org/learn/scientific-computing-with-python/python-for-everybody/pythondictionaries
What does dict equal after running this code?:
dict = {"Fri": 20, "Thu": 6, "Sat": 1}
dict["Thu"] = 13
dict["Sat"] = 2
dict["Sun"] = 9
{'Fri': 20, 'Thu': 6, 'Sat': 1}
{'Fri': 20, 'Thu': 6, 'Sat': 1, 'Thu': 13, 'Sat': 2, 'Sun': 9}
{'Sun': 9}
{'Thu': 13, 'Sat': 2, 'Sun': 9}
{'Fri': 20, 'Thu': 13, 'Sat': 2, 'Sun': 9}
IT 203L – Platform Technologies
Python for Everybody - Dictionaries: Common Applications
https://www.freecodecamp.org/learn/scientific-computing-with-python/python-foreverybody/dictionaries-common-applications
What will the following code print?
counts = { 'quincy' : 1 , 'mrugesh' : 42, 'beau': 100, '0': 10}
print(counts.get('kris', 0))
2
quincy
0
10
[will return error]
IT 203L – Platform Technologies
Python for Everybody - Dictionaries and Loops
https://www.freecodecamp.org/learn/scientific-computing-with-python/python-foreverybody/dictionaries-and-loops
What will the following code print?:
counts = { 'chuck' : 1 , 'annie' : 42, 'jan': 100}
for key in counts:
if counts[key] > 10:
print(key, counts[key])
annie 42
jan 100
chuck 1
annie 42
jan 100
chuck 1
[Error]
IT 203L – Platform Technologies
EXERCISE:
(Note: follow these video exercise and save your file and output.)
https://www.youtube.com/watch?v=PrhZ9qwBDD8
IT 203L – Platform Technologies
Python for Everybody - The Tuples Collection
https://www.freecodecamp.org/learn/scientific-computing-with-python/python-for-everybody/the-tuplescollection
What will the following code print?:
d = dict()
d['quincy'] = 1
d['beau'] = 5
d['kris'] = 9
for (k,i) in d.items():
print(k, i)
k i
k i
k i
quincy 0
beau 1
kris 2
quincy 1
beau 5
kris 9
1 quincy
5 beau
9 kris
IT 203L – Platform Technologies
Python for Everybody - Comparing and Sorting Tuples
https://www.freecodecamp.org/learn/scientific-computing-with-python/python-for-everybody/comparing-andsorting-tuples
Which does the same thing as the following code?:
lst = []
for key, val in counts.items():
newtup = (val, key)
lst.append(newtup)
lst = sorted(lst, reverse=True)
print(lst)
print( sorted( [ (v,k) for k,v in counts.items() ], reverse=True ) )
print( [ (k,v) for k,v in counts.items().sorted() ] )
print( sorted( [ (v,k) for k,v in counts.keys() ] ) )
print( [ (k,v) for k,v in counts.values().sort() ]
IT 203L – Platform Technologies
EXERCISE:
(Note: follow these video exercise and save your file and output.)
https://www.youtube.com/watch?v=EhQxwzyT16E
IT 203L – Platform Technologies
Download