For this group activity, students should work in small teams. Each team needs a copy of this handout, which contains logical operators, conditions and outcomes to be cut out with scissors.
Imagine your class is having a gift giving celebration. The rules are quite complicated.
Read these carefully as a class to make sure you understand how the game works:
TASK: In your team construct three long, logical sentences to determine your actions when it's your turn in the celebration. Each sentence leads to one of the three outcomes. Note. you do not have to simulate the present giving celebration itself, unless doing so helps with understanding."
CC BY-SA 3.0
In this lesson, students will:
Begin by watching the overview video below:
As a class, write or type out the incomplete pseudocode below, filling in the gaps.
(Note this program is slightly simplified.)
1 BEGIN 2 randomNumber ← random choice of 0, 1 or 2 3 If randomNumber = 0 Then 4 computerPick ← ‘scissors’ 5 Else If randomNumber = 1 Then 6 computerPick ← ______ 7 Else If randomNumber = _ Then 8 ____________________ 9 End If 10 11 Display ‘Scissors, paper or rock?’ 12 userGuess ← input from user 13 14 If __________ = __________ Then 15 Display ‘Tie.’ 16 Else 17 If (computerPick = ‘scissors’ And userGuess = ‘paper’) Or 18 (computerPick = ‘paper’ And userGuess = ________) Or 19 (computerPick = ________ And userGuess = ‘scissors’) Then 20 Display ‘You lose.’ 21 Else 22 Display ___________ 23 End If 24 End If 25 END
This program has three sections (Lines 2-9, Lines 11-12 and Lines 14-24). Discuss the following questions to develop an understanding of the structure.
Q. What is the purpose of Lines 2 to 9?
A. This is where the computer’s pick (scissors, paper or rock) is chosen using a random number.
Q. What is the purpose of Lines 11 and 12?
A. This is where the user makes their pick.
Q. What is the purpose of Lines 14 to 24?
A. This is where the program determines who was the winner, or if there was a tie.
For more on setting up and choosing a language, see Setting Up.
The game rejects invalid user input. If the user types anything other than ‘rock’, ‘paper’ or ‘scissors’, they must try again.
This is called electronic validation, and is an important part of the user experience. Ideally, a solution should reject invalid data, and provide useful feedback or error messages to the user.
Use the incomplete table below to discuss how different programs and user interfaces do electronic validation. You may be able to think of some more situations.
|App or program||Situation||How might the app validate my input?|
|Scissors, paper, rock game||I might enter the wrong word.||IF word is not ‘rock’, ‘paper’ or ‘scissors’ THEN make me type again.|
|Farming game on my phone||Buying a new animal, but I might not have enough gold.||IF not enough gold THEN ‘Buy’ button is greyed out.|
|Online address form||I might forget a digit in my phone number.|
|I might misspell my state.|
|Mining and forging simulator||I might try to combine two items that can’t be combined.|
|Text adventure||I might type GO NORTH, but there is no path North from here.|
These challenges use the skills covered so far. By writing or modifying their own programs, students have an opportunity to demonstrate Application and Creation.
Edit the original game to work 'best out of three' – that is, the winner is the one who won the most games after three rounds.
You’ll need to add an additional variable to keep track of the number of times the user has won, then check it at the end of three rounds. You might also need a variable to keep track of the number of the times the computer has won.
Note: You do not need to use a loop, since loops will be officially covered later in this course. You may instead retype or copy and paste your existing code.