A practical lesson introducing the Python programming environment focusing on the distinction between the programmer and the user, and writing suitable prompts to get user input. There is also an extension activity at the end which deals with a variety of input devices and sensors. We are learning ...
So that we can ...
You are here to learn about computer science. That means that you will need to take on two roles - that of the user of the computer and that of the programmer.
PROGRAMMER : Generally an expert in programming, is in charge of solving the problem and making sure that she gets all the information she requires from the users. Has a fixed idea of what the program should do.
USERS : Generally not experts in programming, don't know (or care) how the program works as long as they get the right answer at the end. Will often not have time to read user manuals and so will need to be given lots of prompts as to the information that the programmer requires to solve their problem. Often impatient.
Task 1.1 Thinking about roles
Where we learn about the difference between programmers and users
Consider the different needs of a computer user and a computer programmer. What does the programmer want? What do the users want? Pair up with a partner and discuss. Be prepared to share your ideas with the rest of the class.
It is the programmers job to gather the data that he / she requires from the users of the computer to enable the problem to be solved. He / she needs to think carefully about what that data is and how it should look.
The data that the computer program may need to gather describes characteristics of an object.
The data (or rather the memory the data is stored in) has to be given a name to help us and the computer to identify it later on. These are called identifiers (or names in some programming languages). There are two types of identifiers which are variables (identifiers who's values can change) and constants (identifiers who's values can't change).
Where we learn how to describe objects by identifying their important characteristics
Download and complete the worksheet, Describing Things. This exercise is designed to help you identify named characteristics of objects. Make sure you check your answers before handing the worksheet in for checking!
Assignment is the name used to describe the method used to store data in a computer system by putting it in the computers memory and attaching an identifier to it so it can be found later on. You can think of it as attaching a label to your keys to help you find them in the key box ...
Programmers use a simple language called pseudocode to write assignment statements to show how data is stored and, most importantly, how it is identified by the computer program ...
The first statement can be read "store the value 8.5 in the computers memory and label it shoesize so we can find it again later if we need it" - that's a bit long winded which is why we would tend to write
shoesize ← 8.5 ! Notice the leftwards facing arrow - this is called an 'assignment operator'.The names are sometimes known as variables or identifiers because the values they identify can vary ...
names / variables / identifiers
Where we learn about assignment and how computers store data in memory
When you ask the user for data, the programmer needs to use command prompts rather than questions and usually needs to give the user some idea what the data should look like so that they can attempt to type it in in the correct way. For example ...
If I want the user to select a certain category of film for instance, I might write a command prompt like this ...
Command prompts are a like closed questions in a questionnaire.
Where we learn how to write suitable input prompts
Where we learn practical methods for getting data from the user
The Python programming environment (which hopefully you have already met) allows us, the programmers, to ask them, the users, for information. Sometimes, the confusing thing is that you can be the programmer and the user - you are both at the same time!
Carry out the tasks using the Python programming environment, IDLE. Record what you are doing in a word processed document using a combination of screenshots and written explanation.
Open the Python programming environment, IDLE, use the online TRYTHON shell or create a new Repl.
This is called the shell and the three chevrons ( >>> ) are called the prompt. To the right of the prompt should be a flashing cursor which is where we type instructions. The shell is used mainly for development and trying things out.When we use assignment statements in Python, we don't use the leftwards facing arrow (←) that we use in pseudocode (can you find it on the keyboard?). Instead, we use an equals sign, = . Try typing the following commands exactly, one at a time at the prompt, pressing Enter after each one (don't type the >>> - that's already there!) ...
Write about what happened. Make sure you use the word assignment and the word reassignment in your explanation.
Rather than assigning the value of
forename explicitly, we now know how to ask the user for it using a command prompt. Python uses the instruction input(prompt) to allow us to do this. Try typing the following input commands exactly as written, one at a time, at the prompt, pressing Enter after each one. In the second line, the blue text will appear - just type John and press the Enter key.
Write about what happened, using this Python code as an example. Try to use the word 'reassignment' in your explanation. How is this method better than the first one you tried? Print out your word processed document for your notebook / folder.
Task 3.2 Silence and whiteboards
Where we learn about the rules for naming 'identifiers'
Shhhhh!
Read the passage below and make some handwritten notes on paper in silence ...
Now carry out the activity as a class with your whiteboards.
Task 3.3 Practical examples of input statement Where we learn practical methods for writing input statements
For each of the following situations, construct a suitable input statement to gather the required data, type this in at the shell, provide a suitable value to test the statement works and then echo the value (using
print() ). Use the examples you tried earlier to help you. For example, to ask the user to enter their hair colour ...
For this exercise, create a word processed document with a suitable header and footer. Record what you have done using a combination of screenshots and written explanation.
Open up the Python programming environment, IDLE or you can use the Python programming environment, IDLE or use the online TRYTHON shell - whichever you prefer.
Construct suitable prompts to store and print out the user's choices in each case. Document what you have done using screenshots and written explanation in a word processed document. I have done the first one for you ...
Print out the word processed document for your notebook / folder.
The first thing to realise is that constants are not variables! A constant is a value stored in memory that is identified by an identifier (name) but which cannot / should not be changed. But why would we need them?
Task 4.1 What's the point of CONSTANTS? We we learn about the advantages of using names constants
Your teacher will remind you how to create a Python script. Type the following code in the script (you can copy and paste it if you want to!)
LANGUAGE is used to identify the word "Python" in memory? The identifier is written in CAPITAL LETTERS to tell us that it is a constant. How many times is LANGUAGE used in the script?Save the script in a suitable place in your documents and run it by pressing the F5 key on the keyboard. What do you see? What has printed instead of the constant LANGUAGE in the print() statements?Now try changing the first line in the script to ...
Type the following code in a new Python script (you can copy and paste!)
The IPSO model of computer systems with the inputs highlighted in green
Getting data into a computer system is kinda fundamental. Without data to process, the computer can't do anything useful. One place data comes from are manual input devices. Here is a list of some common ones ...
... and here is a list of automatic input devices or sensors ...
A sensor is a device that measures analogue physical or environmental characteristics and may convert them into a digital signal as well - sensors detect changes in the environment. The input devices we have seen so far have involved a form of human interaction. Sensors do not need this human interaction, instead they respond to the environment automatically.
The input device or the sensor is responsible for converting the analogue world into a digital world for processing by the computer itself. This analogue to digital conversion either happens in the computing device or in a separate device designed to carry out that specific process.
Task 5.1 Input devices and sensors
Where we learn about the identity, applications and function of various input devices
Convert the lists above into two mind maps. Use lots of colour and pictures to make your mind map more interesting to look at - this will also mean that it will be easier to remember. Try to think about the situations in which each device or sensor may be used and add this to your map as well.
Give your maps to your shoulder partner and ask him / her to tell you want went well and what could be improved. Make sure you make the improvements suggested and hand in both maps to your teacher.
Task 5.2 Waymo - Google's self driving car project
Where we learn about the application of sensors to a contemporary situation
Visit the Waymo website which is the home of Google's self driving car project. Investigate and explain what input devices (including sensors) you might need in a driver-less car of the future. Try and think about the following:
Use all the research you have collected to make a poster about the application of sensors to the concept of the self driving car. Make sure you mention how each of the sensors listed (and any others if you can find them) are used in this, or other, autonomous vehicles. Hand your poster into your teacher when you have finished.
Robots also use sensors to detect their environment. There are a lot of videos on YouTube from Boston Dynamics which you should watch and be amazed! Talk to your computing teacher about what you have seen.
FAQ Frequently Asked Questions
Q : Are there alternatives to camelCaps?
A : It's absolutely fine to use other systems; quite often, programmers separate the words in the variable with underscores and avoid capital letters altogether. As long as there are no 'illegal' characters, it's fine.
Q : What is the maximum number of variables you can have in a script?
A : The only limit to the number of variables you can have in a script is the available memory required to store them.
Q : Why do we use pseudocode?
A : Good question! We use pseudocode because it is programming language 'non-specific' and should allow anyone to convert the algorithm into any programming languages. It literally means 'false code'.
|