ITSC203 Lab2

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Python

Offensive and Defensive Tool Construction


Table of Contents
EVALUATION:...............................................................................................................................1
Objectives......................................................................................................................................3
Background Reading.....................................................................................................................3
Important Information.....................................................................................................................3
Problem 1 (15 pts).....................................................................................................................4
SUBMISSION.............................................................................................................................4
Problem 2 (25 pts).....................................................................................................................5
Criteria:.......................................................................................................................................5
Question(s):................................................................................................................................6
SUBMISSION.............................................................................................................................6
Problem 3 (30 pts).....................................................................................................................6
Criteria: 24pts (includes the 5pts for criteria 4)..........................................................................6
QUESTIONS (6pts)....................................................................................................................8
SUBMISSION.............................................................................................................................8

EVALUATION:
1 Problem 1 15
2 Problem 2 25

TOTAL MARK 40

© 2017, Southern Alberta Institute of Technology. All rights reserved.


This publication and materials herein are protected by applicable intellectual property laws.
Unauthorized reproduction and distribution of this publication in whole or part is prohibited.

For more information, contact:


Director, Centre for Instructional Technology and Development
Southern Alberta Institute of Technology
1301 16 Ave. N.W., Calgary, AB T2M 0L4
Offensive and Defensive Tool Construction
Python Programming III
Objectives
This lab focuses on the following objectives:
 Analyze the Linux filesystem using Python.
 Explore the use of python in building basic tools to gather information about the
filesystem.
 Use variables, expressions and statements, lists, dictionary, functions in Python.
 Use built-in and external modules to assist in the development of Python Tools.

Background Reading
 Read chapters 6–10 in How to Think Like a Computer Scientist: Learning with Python,
available at www.greenteapress.com/thinkpython/thinkCSpy.pdf.
 https://docs.python.org/3.8/

Important Information
YOU MUST PRESENT IMAGES OF YOUR CODE BEING EXECUTED. DO NOT
SUBMIT YOUR ANSWERS IN THE DOCUMENT. CREATE A BLANK DOCUMENT
AND SUBMIT YOUR ANSWERS THERE.

YOU WILL LOSE MARKS FOR NOT FOLLOWING THE ABOVE


REQUIREMENTS.

All scripts must have the following elements:


1. File and Header comments, which follows the following format:
# Filename: m##XXX.py
# Author: Thunder Cat
# Course: ITSC203
# Details: This exercise checks to see if students read the suggested items or
# prior to class or doing the labs.
# Resources: https://www.cs.siue.edu/programming-style-guide

2. Comments on lines where you used some unique computation that might be tricky to
comprehend a month later.
list1 = [x for x in range(20) if x % 4 == 1] # Using list comprehension to ….
Problem 1 (15 pts)
Using the flowchart and sample output, generate the Python code that will produce the same
behavior.

Examples of the program executing is shown


below:

SUBMISSION
1. Submit your python code and the screenshot(s) of your code working.

Food for thought: How would taking the time to plan, organize your thoughts and
approach before writing code benefit the overall programming experience?
Problem 2 (25 pts)
You will create Python code to output all the keywords available to you in the Language.
There is a builtin module named keyword that you will use to create a list of keywords. Do not
manually type in the keywords. Instead you can place the following lines at the top of your
python code. This is the only module you are allowed to use.

Figure 1: Example showing how to include the keywords from the keyword module.

Figure 2: Example of the code generating output. The figure shows the result of printing the
keywords in a tabular output

Criteria:
1. The field width used for each word should be no more than the width of the longest
keyword plus 2 extra spaces.
a. So, if the longest word is 10 the width used for each word is 12.
2. The words should be right justified in the field.
3. Your output should have 5 columns as shown in the image
4. IMPORTANT: Notice that the words are arranged alphabetically in the output.
a. This will require you to programmatically consider that when sorted, the list will
place words that start with uppercase first. You will change that behavior.

b. Try the following code in your interpreter to understand statement 4a:


Question(s):
1. For Criteria 4, you are told that the default sorting places the words alphabetically, but
also that the words beginning with an uppercase letter come first. Why does the output
show words beginning with an uppercase letter first? 2pts

SUBMISSION
2. Submit your python code and the screenshot(s) of your code working.

You might also like