Visualise line by line code execution in Python

I stumbled across this website that allows you to visualise line by line execution ina Python program. This may be useful for students who are unclear about how a function (or blocks of code) run within a program:

http://pythontutor.com/visualize.html#code=def%20hi%28name%29%3A%0A%20%20%20%20print%28%22hello%20%22%20%2B%20name%29%0A%20%20%20%20%0Ahi%28%22bob%22%29%0Ahi%28%22jeff%22%29&cumulative=false&curInstr=8&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=3&rawInputLstJSON=%5B%5D&textReferences=false

This was recommended by Al Sweigart in his Automate The Boring Stuff with Python (https://automatetheboringstuff.com/)

FutureLearn – Object Oriented Programming in Python

I came across this course on the Raspberry Pi Certified Educators Course this October. It piqued my interest as it uses a text based adventure game to introduce OOP concepts to learners.

I had previously done this with an idea of a Space Invaders game using Visual Basic.NET. This was a fun introduction to concepts and it is easy to create classes and objects in VB. However my current cohort of learners are mostly unfamiliar with VB and have a better grasp of Python.

The course is written by Laura Sach, who I finally met at PiCademy after years of following her on Twitter. And I  thouroughly recommend it as an accessible way of understanding Object Oriented Principles in Python

https://www.futurelearn.com/courses/object-oriented-principles/

Basic Project: Building an Office Desktop Mini PC

Basic Project
Building an Office Desktop Mini PC (40 marks)

 

The Project Brief
Your task is to build a mini Desktop PC for use in
an office.
The PC is to be used for tasks like word processing letters, accessing databases and editing spreadsheets so it does not require any of
its components to be particularly powerful.

You have been given a budget of £500 to purchase the following hardware and software.

  •  a mini desktop case
  • Ÿ all the necessary components to fit inside the case
  • Ÿ a 15” flat screen monitor
  • Ÿ a keyboard and mouse
  • Ÿ stereo speakers
  • Ÿ an operating system
  • Ÿ applications software (word processor, spreadsheet and database)
  • The Report

    Your task is to search for all the required hardware and software and write up a
    report on your choices.
    Your report should include the following pages:
    1. A cover page which includes a title, your name and your class.
    2. An index page listing all the hardware and software you are going to
    purchase.
    3. A page for each of your purchases. Each page should include a heading, a
    picture, the price and a brief description of each purchase.
    4. A page listing the price of each device and a total for your purchases.
    5. A bibliography listing the websites you used during the project.

  • Teaching_Notes_for_Building_a_Computer

Heads Tails Heads – probability problem

Problem:

  1. Write a problem to simulate the tossing of a sequence of successive coin tosses.
  1. Search the suitably generated sequence to find a particular pattern, e.g., HTH. Report where this sequence was found – after how many flips in the generated sequence. Allow the user to enter the pattern to look for via the UI (User Interface).
  1. Modify your program to repeat steps 1 and 2 a variable number of times; allow the user to specify this value in the UI. Each repeat should use the same search pattern, but a new sequence of source coin tosses.
  1. Modify your program to keep track of where the pattern was found in each generated sequence. Report the overall average number of coin tosses required to the find the search pattern across all of the repeats.
  1. If your program is correct, you will find that the average number of tosses necessary to find the search pattern HTH is 10, however, HTT it is 8. Why is this (this is another conditional probability problem)?

Continue reading “Heads Tails Heads – probability problem”

Poundland Pedagogy

We were asked to go to Poundland with £10 to spend on getting items that would help us teach a Computing lesson. My colleague and I chose to teach the fundementals of OOP and objects usin a selection of toys that we bought – eg some rubber balls, plastic cars, dinosaurs etc.

Here is the outline of teh mini lessonw e gave to our peers:

 

OOP – Classes, Sub Classes, Inheritance, Properties & Methods

STARTER Get toys out on the table

“What are all these items?” Answer – hopefully “Toys”

These items are all part of the Class of “Toys”

They have similar properties – you can play with them – what else??

What groups can you see here? Get toys and group them by type – eg cars, animals, soft toys

These can be called sub classes which inherit characteristics from the parent class

Pick up two cars.

These are both in the class “Car”

Eg Yellow car and blue car

“These are instances of Car – they are objects or the class Car”

We could name them “YellowCar” and “BlueCar” – or Car1 and Car2

Properties

Each car has properties – pieces of information about each car – eg

  • Color
  • Size
  • Number of Doors etc

Can you think of any others?

Properties are essentially static – you can’t easily change them – just read the value

Can you think of some properties of any of the other groups of classes?

E.g. Dinosaurs –

  • Size
  • Number of legs
  • Has it got spikes?

 

Challenge can you think of a property for the Toys superclass? (eg suitable age, material made of, needs batteries?)

Properties of the parent class are automatically “inherited” by the sub classes

So if the Toy parent class has a property of “suitable age” then the Cars classes will inherit it, so it will also have that property.

OOP-hierarchy

Methods

Methods are the actions that an object can perform

Eg A car can drive or stop

A Dinosaur can attack

A ball can bounce or be thrown