Lecture 31 – Practice Exercises 7

Slides:



Advertisements
Similar presentations
Case studies over control structures and iterative structures Instructor – Gokcen Cilingir Cpt S 121 (July 6, 2011) Washington State University.
Advertisements

1 Lab Session-II CSIT 121 Fall 2000 Visual Studio Introduction Lab-1 Explanation and Demos Debugging Tips How to add new files to your projects How many.
Introduction to Python and Regular Expressions in Python Lecture 4.
CS1061: C Programming Lecture 23: Review; Examination Details A. O’Riordan, 2005.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Files in Python Input techniques. Input from a file The type of data you will get from a file is always string or a list of strings. There are two ways.
1 Python Chapter 4 Branching statements and loops © Samuel Marateck 2010.
Geography 465 Assignments, Conditionals, and Loops.
COMPSCI 101 Principles of Programming Lecture 27 - Using the Canvas widget to draw rows and columns of shapes.
The if statement and files. The if statement Do a code block only when something is True if test: print "The expression is true"
17. Python Exceptions Handling Python provides two very important features to handle any unexpected error in your Python programs and to add debugging.
Sorting and Modules. Sorting Lists have a sort method >>> L1 = ["this", "is", "a", "list", "of", "words"] >>> print L1 ['this', 'is', 'a', 'list', 'of',
Python Programming Chapter 6: Iteration Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
If statements while loop for loop
COMPSCI 101 Principles of Programming Lecture 25 – Nested loops, passing mutable objects as parameters.
Python Mini-Course University of Oklahoma Department of Psychology Day 4 – Lesson 13 Case study: Word play 05/02/09 Python Mini-Course: Day 4 – Lesson.
Variables and Expressions CMSC 201. Today we start Python! Two ways to use python: You can write a program, as a series of instructions in a file, and.
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
Printing in Python. Printing Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
Debugging and Printing George Mason University. Today’s topics Review of Chapter 3: Printing and Debugging Go over examples and questions debugging in.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
Next Week… Quiz 2 next week: –All Python –Up to this Friday’s lecture: Expressions Console I/O Conditionals while Loops Assignment 2 (due Feb. 12) topics:
Trace Tables In today’s lesson we will look at:
Agenda Introduction Computer Programs Python Variables Assignment
Topic: File Input/Output (I/O)
Lecture 5 of Computer Science II
Topic: Recursion – Part 2
Topic: Functions – Part 1
CompSci 101 Introduction to Computer Science
Topic: Iterative Statements – Part 1 -> for loop
Introduction to Programming
BIT116: Scripting Loops.
Topic: Python’s building blocks -> Statements
Topic: Python’s building blocks -> Variables, Values, and Types
CMPT 120 Topic:  Case Study.
Topic: Functions – Part 2
Think What will be the output?
INF 231 Enthusiastic Study/snaptutorial.com
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
File Handling Programming Guides.
Structured Program Development in C
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
Fractional Equations Chapter 7 Section 7.4.
Programming In Lesson 3.
Learning to Program in Python
CSc 110, Spring 2017 Lecture 4: Nested Loops and Loop Figures
Introduction to Programming
CISC101 Reminders All assignments are now posted.
Introduction to Computer Science
Building Java Programs
Python 4 and 5 Mr. Husch.
Introduction to Programming
For loop Using lists.
Starter Activities GCSE Python.
CMPT 120 Lecture 12 – Unit 2 – Cryptography and Encryption –
Topic: Iterative Statements – Part 2 -> for loop
def-ining a function A function as an execution control structure
CMPT 120 Lecture 10 – Unit 2 – Cryptography and Encryption –
CMPT 120 Lecture 13 – Unit 2 – Cryptography and Encryption –
CMPT 120 Lecture 19 – Unit 3 – Graphics and Animation
Lecture 17 – Practice Exercises 3
Topic: Where to put functions in a program
Lecture 20 – Practice Exercises 4
Lecture 20 – Practice Exercises 4
Lecture 23 – Practice Exercises 5
Lecture 17 – Practice Exercise 3 SOLUTIONS
Introduction to Computer Science
CMPT 120 Lecture 26 – Unit 5 – Internet and Big Data
Review and Instructions
Presentation transcript:

Lecture 31 – Practice Exercises 7 CMPT 120 Lecture 31 – Practice Exercises 7

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

Question 1 – Exploring Lists of Lists Have a look at this code https://repl.it/repls/FuzzyGlitteringTexts 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):

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 1-character high

Question 2 – Exploring File I/O a) Have a look at the 5 demos in this code https://repl.it/repls/IllSomePasswords What do they do? b) Problem Statement: Write a Python program that reads the file words.txt found here: http://greenteapress.com/thinkpython2/code/words.txt 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

Question 3 – a) Selection Sort Visualize the execution of the Selection Sort using https://visualgo.net/en/sorting 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,____________________________

Question 3 – b) Insertion Sort Visualize the execution of the Insertion Sort using https://visualgo.net/en/sorting 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?