Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 1, Day 3 Lazy Coding 29 June 2016.

Similar presentations


Presentation on theme: "Week 1, Day 3 Lazy Coding 29 June 2016."— Presentation transcript:

1 Week 1, Day 3 Lazy Coding 29 June 2016

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

3 Data Structures Containers and Lists Iteration Dictionaries Day 3 Plan

4 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.

5 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.

6 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!

7 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.

8 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.

9 Data Structures Iteration

10 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.

11 Python for loops

12 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.

13 Data Structures Dictionaries

14 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.

15 Python Dictionaries

16 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

17 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.

18 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!

19 Now for the Challenges! 💪🏆💪🏆


Download ppt "Week 1, Day 3 Lazy Coding 29 June 2016."

Similar presentations


Ads by Google