Practice Worksheet-Datatypes Answers Rushabh 8B6

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

THE WESTMINSTER SCHOOL, DUBAI

COMPUTER SCIENCE
Term II, 2020-21
YEAR:08

Practice Worksheet: Rushabh Bhosale 8B6

Starting Activity
Find out where the name ‘Boole’ came from and what a ‘Boolean variable’ is. Write
your answer(s) in the space below:

In computer science, the Boolean data type is a data type that has one of two possible values
which is intended to represent the two truth values of logic and Boolean algebra. It is named after
George Boole, who first defined an algebraic system of logic in the mid 19th century.

Task 1 – Four Data Types


1. There are four types of data you need to know for your GCSE. You can find out
which data type a variable has by writing type(variable). Complete the table
below by copying and running each piece of code and writing down the data
type. The first one has been done for you:

Code Data type of Variable


str
Str
Int
Float
(capital T!) Bool
(capital F!) Bool

2. The type function returns the data type of an expression.


For each of these expressions, first predict the data type then use the type
command to see if your prediction was correct.

Expression Predicted data type Type command Result ( √ or X )


“hello world” Str type("hello world") Correct
False Bool type(False) Correct
15 Int type(15) Correct
35.6 Float type(35.6) Correct
-999 Int type(-999) Correct
“15” Int type(“15”) Correct
“False” Bool type(“False”) Correct
True Bool type(True) Correct
0.001 Float type(0.001) Correct

3. Copy and run this code in the interactive shell.

4. In your own words, explain what the code does:


The code prints the both variables on the screen. myName and myAge are the
values. The output they give is the text and number written after the equals sign.
The print code prints the values' outputs on the screen. For example if the code is,
myAge = 14
(Print (myAge))
The int 14 will be printed because the output of the value is 14.

5. Complete this table to describe the four data types.


Data Python
Explanation Example
type abbreviation

integer int It is a whole number 25

string str It is words and letters “hello world”

float float It is decimals 2.61

It is like the IF function


boolean bool and gives the output “True”
true or false

Hint: Quotation marks are used to show the start and end point of a string, e.g. “this is a
string”

Task 2 – Your Story


Write a short story using a number of variables (e.g. Hero, Villain, Location). Write down
the name of each variable below and the data type which it uses:

Variable Name Data Type Variable Name Data Type


“You are a hero” Str 0.00001 Float

100 Int “Is the villain” Str

“Villains are the Str “The hero saves a Str


worst” person”
“Hero is much Str “ villain is Str
better” deafeated”

Task 3 / Extension
Continue with your story. Try to include at least one string, one integer and one floating
data type in your variables (you will struggle to use Boolean).

You might also like