Week 1, Day 3 Lazy Coding 29 June 2016.

Slides:



Advertisements
Similar presentations
Microsoft® Small Basic
Advertisements

Introduction to Computing Science and Programming I
Lilian Blot CORE ELEMENTS COLLECTIONS & REPETITION Lecture 4 Autumn 2014 TPOP 1.
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Lecture 4: Calculating by Iterating. The while Repetition Statement Repetition structure Programmer specifies an action to be repeated while some condition.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 5 Looping.
1. Understand the application of Pseudo Code for programming purposes 2. Be able to write algorithms in Pseudo Code.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Loops and Files. 5.1 The Increment and Decrement Operators.
1 Standard Version of Starting Out with C++, 4th Brief Edition Chapter 5 Looping.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
Chapter 7 Problem Solving with Loops
CPSC 217 T03 Week V Part #1: Iteration Hubert (Sathaporn) Hu.
Count Controlled Loops (Nested) Ain’t no sunshine when she’s gone …
9. ITERATIONS AND LOOP STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours.
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
CMSC201 Computer Science I for Majors Lecture 07 – While Loops
Repetition Structures
ECE Application Programming
Week 1, Day 2 Programmatic mastery
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
Introduction to Python
Lecture 6 Repetition Richard Gesick.
Repetition (While-Loop) version]
Selection and Python Syntax
Python: Control Structures
Lesson 05: Iterations Class Chat: Attendance: Participation
IF statements.
Week 1, Day 4 Snakes Alive 31 June 2016.
Repetition Structures (Loops)
While Loops in Python.
Python - Loops and Iteration
Starter Write a program that asks the user if it is raining today.
Iterations Programming Condition Controlled Loops (WHILE Loop)
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Logical Operators and While Loops
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
Learning to Program in Python
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Lesson 05: Iterations Topic: Introduction to Programming, Zybook Ch 4, P4E Ch 5. Slides on website.
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
Repetition Structures
Java Programming Loops
Do While (condition is true) … Loop
Repetition Structures
Intro to Computer Science CS1510 Dr. Sarah Diesburg
3.1 Iteration Loops For … To … Next 18/01/2019.
Computing Fundamentals
Building Java Programs
CISC101 Reminders All assignments are now posted.
Flowcharts and Pseudo Code
CHAPTER 6: Control Flow Tools (for and while loops)
Java Programming Loops
Using Decision Structures
Winter 2019 CISC101 4/16/2019 CISC101 Reminders
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Loops.
While Loops in Python.
CMPT 120 Lecture 13 – Unit 2 – Cryptography and Encryption –
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Week 7 - Monday CS 121.
Presentation transcript:

Week 1, Day 3 Lazy Coding 29 June 2016

Day 2 Recap Conditionals Loops Recap ♻♻💡💡 Conditional Statements Boolean Logic Boolean Expressions Loops Loop Statements While Loops Loop Patterns Day 2 Recap Recap ♻♻💡💡

Data Structures Containers and Lists Iteration Dictionaries Day 3 Plan

Data Structures Containers and Lists I like to reference either the receipt program or the exam marks program. In both cases, they will have had to have variables like item1, item2, ... , itemN. Maybe ask them how they would use these variables in a loop -- they can’t! Instead, say we’re going to combine all of those variables into a single structure.

Firstly talk about what this might be - a shopping list or a list of ingredients. Then talk about what a list or a grouping is - a collection of items for a certain purpose. Link this back to the idea of what data structures are. It’s worth suggesting that a list should contain a single type of item. Python doesn’t enforce this, but life gets complicated when lists have different datatypes inside.

Python Lists Recreate a shopping list from the previous slide. First as a bunch of item1, item2, .. variables, and then print them all (you’ll need to just have a bunch of print statements with hard-coded variable names). Emphasise how much repetition there is and how we don’t like that. Next, show them that we can create a list `items = [“leeks”, “potatoes”, …], and loop through them with a counter loop (as demonstrated yesterday). Much tidier!

Exercise 3.1 – Getting Fruity Write a short program that: Prompts the user to enter their favourite fruit. Compare the user's input to a list of fruits that you, the programmer, have specified. If the user’s fruit is in the list print out a message commenting on the similarities of your fruit preferences, if not print out a commiseration. Get them to build this using a loop first, checking every individual item against the user’s preference. They’ll need some kind of “check” variable which is False to begin with, and which gets set to true when the fruit is identified within the list. Once they’ve sussed that out, introduce the “in” keyword, and get them to rewrite the program using in instead.

Exercise 3.1(b) – Getting Fruity Write a short program that: Prompts the user to enter their favourite fruit. Compare the user's input to a list of fruits that you, the programmer, have specified. If the user’s fruit is in the list print out a message commenting on the similarities of your fruit preferences, if not print out a commiseration. The program should run until the user specifies an exit condition This extension is basically just practicing the other loop pattern introduced yesterday - the run-until loop.

Data Structures Iteration

Talk about travel or a journey (the route of the word iteration is iter - Latin for journey). Talk about why you might want to travel over a data structure - to inspect all of the elements or maybe to modify them. The previous exercise pre-empted this idea.

Python for loops

Exercise 3.2 – Getting Fruitier Write a new fruit-comparison program to let the user enter several fruits which they like. After they enter each fruit, you should ask them if there are any more they want to enter. After they’ve finished, print out all the fruit that they like which are also in your own list.

Data Structures Dictionaries

Ask the class to identify what this is Ask the class to identify what this is. They should recognise it as a dictionary - the thing to focus on is the linking of word entries to definitions and pronunciation guides.

Python Dictionaries

Exercise 3.3 – Mark of Authority (MK II) Expand yesterday’s exam score program: Prompt the user to enter how many students Then prompt for a name for each student as well as their marks. Once all of the marks have been captured, print out a table, with one row per student, and columns for each subject

Exercise 3.3b – Mark of Authority (MK II) Expand yesterday’s exam score program again: Add a column showing the student’s average mark across all subjects After the table, print out a list of the students who have passed.

Day 3 Data Structures Recap ♻♻💡💡 Containers and Lists Iteration Dictionaries Day 3 Recap ♻♻💡💡 Go into detail if you can during the recap -- remind people of the specific problems that they encountered during the day, and how they managed to surmount them. It feels good to overcome obstacles, so remind them that what they’ve been doing is difficult, that they’ve come a long way, and that they’re doing a great job already!

Now for the Challenges! 💪🏆💪🏆