You are on page 1of 27

Applied Tech Lesson 1

March 16, 2021

1 Lesson 1: Mind Reader Game - Variables & Data-Types


WARNING: The reference notebook is meant ONLY for a teacher. Please DON’T share it
with any student.
The contents of the reference notebook are meant only to prepare a teacher for a class. To conduct
the class, use the class copy of the reference notebook. The link and the instructions for the same
are provided in the Notes To The Teacher section.

Particulars Description
Topic Mind Reader Game - Variables & Data-Types

Class Description A student learns to create a simple algorithm


for the Mind Reader game that uses artificial
intelligence to predict the player’s next move

Class C1

Class Time 45 minutes

Goal Create a very simple algorithm for the Mind


Reader game
Create variables to store different Python
data-types

Teacher Resources Link to the Mind Reader game


Link to the trial class Google Colab reference
notebook
Google Account
Laptop with internet connectivity
Earphones with mic

Student Resources Link to the Mind Reader game


Google Account
Laptop with internet connectivity
Earphones with mic

1
1.0.1 Class Structure
A class is divided into three parts, as shown in the table below.

Parts Duration
Warm-Up 9 minutes

Teacher-Student Activities 30 minutes

Wrap-Up 6 minutes

1.0.2 Notes To The Teacher


Before beginning the class:
1. Open the ATV - Lesson 1 - Class Copy- v0.3 file by clicking on the link provided in
the Activities section under the title Mind Reader Game - Variables & Data-Types
(Class Copy).
Refer both Reference and Class Copy before conducting the class.
2. After opening the file mentioned in the first point, create its duplicate copy by following the
steps described below:
• Click on the File menu. A new drop-down list will appear.

!
• Click on the Save a copy in Drive option. A duplicate copy will get created. It will
open up in the new tab on your web browser.

2
• In the duplicate copy, click on the Share button on the top right corner of the notebook.
A new dialog box will appear.

3
• Click on the tiny downward arrow next to Anyone with the link can view text. A
drop-down list will appear.

• Click on the More… option. A new page on the dialog box will appear.

4
• Click on the circle next to On - Anyone with the link option. Now, go down and
click on the tiny downward box next to Can edit text. A drop-down list will appear.

5
• Click on the Can edit option. Then click on the Save button. You will be directed
back to the first page of the dialog box.

6
• Make sure that under the Link sharing on section, Anyone with the link can edit
option is selected.

7
• Then click on the Done button.
3. After creating the duplicate copy of the notebook, please rename it in the YYYY-MM-
DD_StudentName_Lesson1 format.
4. Now, finish the Warm-Up section. Afterwards, proceed with the class using the duplicate
copy of the notebook. You can share the link of the duplicate copy (named as YYYY-MM-
DD_StudentName_Lesson1) with the student through the chat window.
5. When a student executes the code for the first time in the duplicate copy that you shared
with them, they may get the following warning:
Warning: This notebook was not authored by Google. This notebook was
authored by xyz@gmail.com. It may request access to your data stored
with Google such as files, emails and contacts. Please review the source
code and contact the creator of this notebook at xyz@gmail.com with any
additional questions.

Cancel. Run Anyway.


6. Ask the student to click on the Run Anyway button.
7. If you see the hat (^) sign on the heading of an activity, give a hats-off to the student at the
end of the activity.
• Single hat sign, i.e., ^ denotes give hats-off for concentration. You have to assess the
concentration level of a student based on their attentiveness and understanding of the

8
concept.
• Double hat signs, i.e., ^^ denotes give hats-off for creativity. It can be an alternative
approach to writing a code for an activity or applying the logic in a totally different
problem statement.
• Triple hat signs, i.e., ^^^ denotes give hats-off for persistence. It is the ability of a
student to not give up on writing code and writing code with minimal teacher support.
8. Every time you execute your code in the Google Colab notebook, please don’t forget to save
it by pressing the Ctrl + S keys (or Command + S keys if you are using a Mac). While
saving the notebook, you or student may encounter the following error:
Save failed

The notebook has been changed outside of this session. Would you like to
overwrite existing changes?

CANCEL YES
Click on the YES button.
9. Occasionally, you may encounter some error such as NameError, ReferenceError,
ImportError or ModuleNotFoundError after executing the code in k th code cell (where
k > 0). Most likely, due to poor internet speed, the Colab notebook might have lost the
information that all the previous codes have been executed already. As a remedy, run codes
in the code cells beginning from the first code cell till the (k − 1)th code cell. For e.g., if the
code in the 5th code cell fails to run because of one of the aforementioned errors, execute the
codes in all the first four code cells again.
10. For every Teacher Action, the teacher is supposed to share their screen with the student.
Similarly, for every Student Action, the student is supposed to share their screen with the
teacher.

1.0.3 Warm-Up
TEACHER
Hi <student_name>! How are you doing?

EXPECTED STUDENT RESPONSE


I am doing good, teacher. How about you?

TEACHER
I am having a good time too, thank you. So, how was your day?
What did you do today?

EXPECTED STUDENT RESPONSE


I went to school. Had my lunch. Played a game and then did my homework
before this class.

9
TEACHER
That's great. I am glad that you are having a good day.
Have you ever tried reading someone's mind? Or came across any Mind
Reading App or any Mind Reading Game?

EXPECTED STUDENT RESPONSE


No

TEACHER
Let's first play a Mind Reading Game in which I will try to read your mind.
Make sure you have a pen and notebook with you. Shall we start?

EXPECTED STUDENT RESPONSE


Yes Teacher.

TEACHER
Here are the step by step instructions: (The visuals for this game are added in the Class cop
1. Pick a number between 1-10. Don't tell me that number. Write
down that number in your book.
2. Then multiply that number by 2 and add 10 to that number.
3. Divide the result by 2.
4. Now subtract the result from the original number which you had chosen
in the beginning. You will get a single digit number from this subtraction.
It is called the "Magic Number"!

So let me guess what is your magic number. Is your magic number "5"??

(Teachers note that the magic number will always be 5, no matter


whatever number the student had chosen. Unless incorrect math has been performed,

10
the answer will always be 5.)

EXPECTED STUDENT RESPONSE


Yes teacher, how did you guess it?

TEACHER
Well that's a secret. This was a kind of Mind Reader game.
There are many Mind Reader Apps available on playstore and Appstore.
Today I want to show you one AI-based Mind Reader game.
In this game, a player clicks on either the 'Heads' or 'Tails' button.
The computer predicts which button a player is going to press.
If the computer predicts the player's move correctly,
then the computer will get 1 point else the player will get 1 point.
The game runs until either the player or the computer reaches a score of 50.
(This gif image is present in Class copy for students to understand the working of this Mind
Note:
- The teacher clicks on the second link provided in the
'Activities' section under the title 'Mind Reader Game' to open the
game. (The link is also there in Class copy)
- The teacher shares their screen with the student.

EXPECTED STUDENT RESPONSE


Student observes.

TEACHER
So, this is a Mind Reader Game. Can you see it?

EXPECTED STUDENT RESPONSE


Yes. I can see it.

TEACHER
Good. Here, 'AI Bot' denotes the computer and 'You' denotes the player
playing this game. Suppose a player clicks on the 'Heads' button and the
computer predicts it correctly, then 'AI Bot' score will increase and the
height of the red bar will also increase. Can you see it?

11
EXPECTED STUDENT RESPONSE
Yes. I can see it.

TEACHER
All right. Now I will stop sharing my screen. You share your screen with

12
me and then play this game. Remember that you have to beat the computer.
The computer should not be able to correctly predict on what button you
are going to click.

Note:
- The student shares their screen with the teacher.
- The teacher asks the student to click on the second link provided in
the 'Activities' section under the title 'Mind Reader Game' to open
the game.

EXPECTED STUDENT RESPONSE


The student shares his/her screen and starts playing the Mind Reader game.
Most likely, the student will lose in the game.

TEACHER
Now that you have played the game, do you want to know how it was able to
predict which button between 'Heads' and 'Tails' you are going to click?

EXPECTED STUDENT RESPONSE


Yes, teacher. I am curious to know how it was able to predict my move.

TEACHER
The computer was keeping a track of your previous inputs, i.e., in the
previous attempts, whether you played 'Heads' or 'Tails'. It was looking
for a pattern in your inputs and based on that pattern, it was predicting
what would be your next move.

Now, you might ask why the score goes only to 50 points. Why not 100 or 10?
The number 50 also has some significance. The computer needs to

13
continually keep a track of your inputs. If the scoring was only till 10
points, then you could have easily defeated the computer because then it
wouldn’t have tracked enough number of your previous inputs. On the other
hand, if 100 points were needed to win the game, then the computer would
have easily recognised the pattern of your inputs by tracking a lot of
your previous inputs. Hence, it would have been nearly impossible for you
to win the game.

I hope you understood everything I told you so far.

EXPECTED STUDENT RESPONSE


Yes, teacher.

TEACHER
Great. Now, I am going to share a link with you. Open the link in the new
tab of your web browser.

Note:
- Share the duplicate copy of the Colab notebook that you created with
the student through the chat window.

EXPECTED STUDENT RESPONSE:


Student opens the duplicate copy of the Colab notebook.

1.0.4 Teacher-Student Activities

In case of the Mind Reader game, we want the computer to randomly predict the player’s inputs.
Therefore, the very simple version of the Mind Reader game algorithm should implement the
following steps:
After following the above four steps, we should get the following algorithm:
import random

14
player_input = input("Enter either 0 or 1: ")
print("You entered", player_input)
predict = random.randint(0, 1)
print("Computer predicted", predict)

Activity 1: The print() Function Let’s print "You entered" message using the print()
function. The text "You entered" is an input to the print() function. The output would also be
the same.
When using the print() function, enclose the text that you need to print either in the single-quotes
('') or in double-quotes ("").
To run the code, either click on the Play button on the left-hand side of the code cell or press the
shift and enter keys together while you are active in the code cell.
[ ]: # Teacher Action: Print "You entered" message to a player using the 'print()'␣
,→function.

print("You entered")

You entered
So, we have printed "You entered". Notice that the text written after the hash (#) symbol is not
a code rather it is a plain text. Anything written after # is read as a plain text by Python. Such
plain texts are called comments made by a coder to briefly explain the code.
Now you print "Computer predicted" message using the print() function.
[ ]: # Student Action: Print "Computer predicted" message to a player using the␣
,→'print()' function.

print("Computer predicted")

Computer predicted

15
Activity 2: Variables And Data-Types^ What are data-types in Python?

NOTE:
The T in True and F in False must be capital because Python is case-sensitive.
A variable can store only one value at a time.
Now, let’s practice Python variables by storing the various information about Mercury and Saturn
planets in variables.

16
[ ]: # Teacher Action: Create 4 different variables and store the planet name,␣
,→diameter, gravity and ring values of the first planet in the variables.

# 1. Store a string value in a variable


planet1_name = "Mercury"

# 2. Store an integer value in a variable.


planet1_dia = 4789

# 3. Store a float-point number in a variable.


planet1_gravity = 3.7

# 4. Store a boolean value in a number.


# Python can also store a boolean value, i.e., either True or False.
# The 'Yes' or 'No' values are generally represented as True or False in Python.
,→ It cannot understand Yes or No.

planet1_has_ring = False

# If we run the code cell, we won't get any output. But the values will be␣
,→assigned to these 4 variables.

So far we have stored 4 different types of values in 4 different variables. Now, let’s print the values
stored in these variables using the print() function.
[ ]: # Print the values stored in all the 4 variables.
print(planet1_name)
print(planet1_dia)
print(planet1_gravity)
print(planet1_has_ring)

Mercury
4789
3.7
False
As a good practice, name a variable in such a way that it reflects the nature of the value stored in

17

You might also like