6 – Putting it all Together

🎯 Learning Objectives

Develop the Programming and DevelopmentAlgorithms Learning Strands:

  • Combine iteration and selection to control the flow of program execution.
  • Use Boolean variables as flags.
💬 Key Vocabulary
  • Iteration
  • selection
  • conditions
  • Boolean (or logical) operators and expressions
  • counting
  • flags

🔎 More Branches

Last lesson, you…

  • Used iteration (while statements) to allow the flow of program execution to include loops
  • Used variables as counters

In this lesson, you will…

  • Use three control structures (sequence, selection, and iteration) to build a more complex program
  • Use Boolean variables, operators, and expressions
  • Take a quiz, to assess what you have learnt

📖 Activity 1 – Guess my Lucky Number

  • We can add a while loop to this code to allow the game to continue until the correct answer is chosen.
  • To do this we use something called a flag. This can be a boolean value (True or False) or any other kind of variable.
  • In this code we have used a boolean variable called guessed that we set as False at the start.
  • Then the while loop runs as long as guessed is equal to False.
  • However the code never changes guessed to True, go to Activity 2 to fix this.

📝 Activity 2 – Lucky Number Revisited

  • Download the Activity 2 worksheet to your Home Drive.
  • Start from the code you made above with your teacher live coding and pair and extend it by following the instructions.

📖 Logical Operators in Python

In this lesson, you…

  • Used three control structures (sequence, selection, and iteration) to build a more complex program
  • Used Boolean variables, operators, and expressions
  • Took a quiz, to assess what you have learnt

In this unit you

  • Explored what basic programming structures look like in Python
  • Built your first Python programs

📝 Where do we go from here?

Project – About me

Write a Python program to tell people about yourself (rpf.io/about-me).

Project – Rock, paper, scissors

Make a ‘Rock, paper, scissors’ game and play against the computer (rpf.io/rock-paper-scissors).

Project – Story time

Create a program that generates a random story, based on what the user types in (rpf.io/storytime).

Project – What’s the password?

Create a program that asks the user for a (pre-specified) password. The user is allowed a maximum of three attempts at entering the correct password, otherwise access will be denied.

This is very similar to the number guessing game that you developed in the last lesson.

Project – The subtraction game

In the subtraction game, two players start with a heap of objects (matchsticks, toothpicks, etc.) and take turns removing one, two, or three objects from the heap, until none remain. The winner is the player that takes the last object from the heap (although there are versions of the game where the player that takes the last object loses).

Create a program where two players play the subtraction game, or where a human player plays the subtraction game with the program as an opponent. The number of objects that the players start with can be randomly selected at the start of the game.

There is a simple winning strategy for the subtraction game and its more general version called ‘nim’. This is the reason why it was one of the first games to be automated. Nim-playing machines like Westinghouse Electric Corporation’s Nimatron and Ferranti’s Nimrod made their appearance in the 1940s and 1950s.

🏅 Badge it

🥈 Silver Badge
  • Complete the Activity 2 – Guess the Number task with all of it’s steps and upload the worksheet to bournetolearn.com.
🥇 Gold Badge
  • Complete Explorer Task 1 – More Information and add a screenshot of your code to the Worksheet and upload to bournetolearn.com.
🥉 Platinum Badge
  • Complete Explorer Task 2 – Randomness and add a screenshot of your code to the Worksheet and upload to bournetolearn.com.