Page 63 - Computing Book 8
P. 63
Programming Robots and Single-Board Computers Class 8
Running Python as a Script On IDLE- A script or scripting language is a feature of computer language
with a series of commands within a file that is capable of being executed. Scripts are just the piece of
code, in which the code is written in the form of scripts and get executed. Error checking is done
when the code is executed or run.
• On Python IDLE click File and then New File.
• In the resulting window type the following program and then save the file as “Test1.py” in
the default location.
Program Output
X=10
Y=5
Z= X+Y
print(Z)
• Then press F5 to execute the program.
• The program output will be 15.
Variables
A Variable is the storage placeholder for text and numbers. It must have a name so that you can find
it again. The variable is always assigned with an equality sign, followed by the value of the variable.
Variables can store data that can be used elsewhere. They’re one of the most powerful tools
programmers can use.
In python IDLE, enter the following statement: score=9
All this does is tell Python that you want to use “score” as a new name for the value
“9”. After this point, whenever Python sees score, it will insert the value “9”.
To demonstrate this, try entering the following:
Print (score) or score
Remember that python executes instructions in order, and you must give “score” a
value before you use it or you will get an error.
This illustrates another great aspect of python and that is dynamic typing. This concept is defined
with respect to the point at which the variable data types are checked. In our code, the variable is
“score” which holds the value “9” which is a number, or we can label it as a data. A variable just
stores the value, whereas the value could be of different data types. The data type defines the type
of data that is stored in the variable. Being said that, dynamic type languages are those in which the
data type checking is done at the run time. We don’t have to declare the data type in our code in
python. Python is smart enough to judge which data type is being held by the variable.
Values:
Values have types, every piece of data has to have a type associated with it so it knows what it is
dealing with. Python sets the variable type based on the value that is assigned to it. Following are
the data types which will be used throughout in coding:
Numbers: Integers and Float
String: any character or text
Boolean: True or False
LIST in Python:
The City School /Academics/Computing Curriculum/Class 8/2020-2021 Page 62 of 75

