Download presentation
Presentation is loading. Please wait.
1
Lecture 31 – Practice Exercises 7
CMPT 120 Lecture 31 – Practice Exercises 7
2
Goals for Today! Exploring Lists of Lists -> good prep for our Assignment 2 Exploring File I/O -> also good prep for our Assignment 2 Practising Selection and Insertion Sort
3
Question 1 – Exploring Lists of Lists
Have a look at this code What does it do? Add code to it to … Create a few more floor patterns Put the string 'MM' at the centre of the first floor pattern Hint: Put the string in the ‘list of lists’ variable aFloor Printing: how differently would these three Python code fragments print the content of the ‘list of lists’ aFloor print(aFloor) for row in range(theHeight): print(aFloor[row]) the function def printFloor(theFloor, theHeight):
4
Question 1 – Exploring Lists of Lists (cont’d)
Imagine you are an interior decorator and would like to see what the floor plan would look like if you were to place a sofa on the east edge of the room Create a function that places a sofa (2 cells deep by 6 cells long), i.e., the string 'SS' along the right-hand side edge of the floor Remember: The cells are 2-character wide and character high
5
Question 2 – Exploring File I/O
a) Have a look at the 5 demos in this code What do they do? b) Problem Statement: Write a Python program that reads the file words.txt found here: and prints only the words it contains that have more than 20 characters (not counting whitespace and newline character) Our Python program must print one word per line
6
Question 3 – a) Selection Sort
Visualize the execution of the Selection Sort using Once you have a good idea how Selection Sort works, sort the following data: 3,38,5,47,15,36,26,27,2,4,19 using Selection Sort and write down what the unsorted section of the data looks like once 3 iterations of Selection Sort have executed, in order words, once data has 2,3,4 in its sorted section: 2,3,4,____________________________
7
Question 3 – b) Insertion Sort
Visualize the execution of the Insertion Sort using Once you have a good idea how Insertion Sort works, sort the following data: 3,38,5,47,15,36,26,27,2,4,19 using Insertion Sort After 3 iterations of Insertion Sort, does the unsorted section of data look the same as in your answer to Question 3 a)? Does the sorted section of data look the same?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.