CS03 : Naming data


https://docs.google.com/presentation/d/1mj65UuKYYqvlOyjZPaNL6gEDp_SlWAac29A5lE4oz3w/preview
A detailed study look of the many ways in which data is classified.  It introduces the concept of the data type and the need to ‘name’ data in order to identify it.  It is suitable for all examination boards.

We are learning ...
  • The difference between  data and information
  • About the fundamental data types that are used in computer systems
  • How to convert data from one type to another
So that we can ...
  • Explain the difference between data and information
    - Computer store binary data
    - The data can represent information (sound, pictures, videos, text and numbers)
  • Recall the names of the fundamental data types and give examples
    - Integer, real, char, string, Boolean
  • Converting one data type into another
    - Temporary type casting
    - Permanent type conversion

CGP The Revision Guide Page 41, 43
CGP Exam Practice Workbook Page 49, 50, 51

# Get Ready.png

Activity 1 What is data and what is information?  I   O   A   E 

Terminology is important when we are talking about data, er, I mean information. I'm not sure what I mean! The following task should help you to clear up any confusion.



Task 1.1 Reading and worksheet
Where you learn about information, data, structured, context and meaning


Reading!

Read the text carefully.

What is data?
 
Data is simply a collection of raw facts and figures. Data is meaningless until we apply structure, context and meaning to it. The act of processing data in this way allows humans to derive information from it. Information is the way in which humans use data (with structure, context and meaning applied) to help them live their lives - it makes data useful.

information ← data + structure + context + meaning
  • Data is raw facts and figures
  • Structure presents the data in a real world form
  • Context puts the data into a valid human situation
  • Meaning is implied from the data, the structure and the context
https://drive.google.com/file/d/1XBYU6iH1gMDFaKVcVtTj6XJ7Z9U1dc9k/preview
Click to engage


In your notebooks / on paper

Make some notes on the information you have read. Make sure you highlight the key terms, like I have.

On the worksheet

Download and complete the worksheet 'Data and information'. Print this and hand it in to your teacher.


Activity 2 Data types  I   O   A   E 

When we tell computers to remember data, we probably expect them to be able to process that data at some point. Unfortunately, computers can only process certain data in certain ways - the type of data is important.


Task 2.1 Data types
Where you learn about the fundamental data types used in programming


Data in the real world comes in many different formats. Computers however can only handle a finite (countable) number of different formats. Computer scientists have narrowed down data to a fundamental set of different types.

More Reading!

Read the following text carefully.

Fundamental data types


Integer : whole numbers (42)
Float / real / decimal : numbers with a decimal point (3.14159265)
Characters : single letters, numbers and symbols (A, B, C, 1, 2, 3, %, $, *, ...)
Boolean : something with two opposite values (True / False, Up / Down, Male / Female ...)
String : a collection of characters / words / sentences

Notes (things that are important)
  • Programmers never really use the term 'decimal', only 'float' and 'real';
  • Characters / strings are 'pictures' of letters, numbers and symbols;
  • Different data types allow you to perform different operations;
  • Any real world concept with two opposite meanings can be represented with a Boolean.
  • Python doesn't have a character type - a character is a single length string in Python.

In your notebooks / on paper

Make some notes on the information you have read. Make sure you highlight the key terms, like I have.

On the worksheet

Complete worksheet 'Data types'. Print this and hand it in to your teacher.



Task 2.2 Handling data types in Python
Where we learn how to determine which data type a value is


The Python programming environment helps us to determine which of the fundamental data types our data is in. There are actually lots of different data types in Python but we'll focus on the five you have learnt about in this section. For this task, carry out the tasks using the Python programming environment, IDLE. Make sure you respond to each activity as you are asked. Type the code in, don't copy and paste!


Get ready to code!

Open up the Python programming environment, IDLE.

At the Python prompt

There is a special instruction in Python called type() which allows Python to work out what type of data it is given to work with. This is important because Python can only carry out certain jobs with certain data types. Enter the following instructions exactly as written at the prompt, pressing  Enter  after each one.

>>> type(12)
>>> type('12')
>>> type(12.5)
>>> type('12.5')
>>> type('H')
>>> type('Hello')
>>> type(True)
>>> type(False)

You should notice that each command responds with either <class 'int'>, <class 'str'>, <class 'float'> or <class 'bool'>. Can you think what these mean and what the type() command is doing?

In your notebook / on paper

Write about what happened using the Python examples to help you and try to explain what you see.

At the Python prompt

Strictly, Python doesn't have a character data type. Characters are treated as strings in Python. However, each character in the string has a special code which is used to identify it to the computer. Type the following instructions at the prompt in the shell, pressing  Enter  after each one ...

>>> ord('H')
>>> chr(72)

Each command should produce an output as well.

In your notebook / on paper

Write about what you have discovered from this part of the task. I would suggest that you research 'ASCII code' to help you to explain what is happening ...

At the Python prompt

Type the following instructions at the prompt in the shell, pressing  Enter  after each one. Don't worry if you get red Traceback errors - in some cases, you should do.

>>> type(True) is bool
>>> type(true) is bool
>>> type(False) is bool
>>> type(false) is bool

With your shoulder partner, discuss what the is command does.

In your notebook / on paper

Write about what you have discovered from this part of the task. Hint : Python is case sensitive - an 'F' is not the same as an 'f' ...



Task 2.3 Type casting and type conversion
Where we learn how to convert one data type to another


Python can only perform certain tasks with certain data types. For instance, it can't turn an integer into upper case! Luckily, Python has functions which cast or convert one data type into another. This is called typecasting if the change is temporary or type conversion if it is permanent.
  • int(value) casts a value in the brackets into an integer
  • str(value) casts the value in the brackets into a string
  • float(value) casts the value in the brackets into a decimal
  • bool(value) casts the value in the brackets into a Boolean (rarely used)


Get ready to code!

Open up the Python programming environment, IDLE.

At the Python prompt

Type the following instructions carefully at the prompt in the shell, pressing  Enter  after each one. Again, you will find some traceback errors occur when you run some of the code snippets. Don't worry - this is meant to happen ...

>>> 12 + 6
>>> '12' + '6'
>>> '12' + 6
>>> int('12') + 6
>>> 'The value of pi is ' + 3.14
>>> 'The value of pi is ' + str(3.14)
>>> 2.78
>>> int(2.78)
>>> str(2.78)
>>> float(3)
>>> float('2.98')
>>> 3.14 * 4
>>> '3.14' * 4
>>> float('3.14') * 4

Discuss what happened with your shoulder partner. You will have to think very carefully ...

I remember doing that once ...

At the Python prompt

Type the following Python commands carefully, pressing the  ENTER  key after each one. There should be no errors so if you get one, you've probably made a mistake somewhere! You don't have to type the # comments.

>>> age = 48
>>> age = str(age) # Permanent type conversion
>>> print('You are ' + age + ' years old')
>>> age = age * 2
>>> print('I am double your age which makes me ' + age + ' years old!')

OK, well try this ...

>>> age = 48
>>> print('You are ' + str(age) + ' years old') # Temporary typecast
>>> age = age * 2
>>> print('I am double your age which makes me ' + str(age) + ' years old') # Temporary typecast

Yes, but never say 'sick' again, please!

What, again!

You might want to perform a type cast rather then a type conversion if you intend to use the variable value later in the code. If you convert the variable from, say, an integer into a string in order to print it, you would have to convert it back again before you could use it as an integer again.

In your notebook / on paper

Write about what you have discovered from carrying out this part of the task. Use some of the Python examples to help you to explain what you have found out.



Task 2.4 Summary questions
Where we answer some easy questions to consolidate our learning


Answer the following questions in full sentences either in a word processed document or on paper, old style.
  1. What data type am I using if I surround character(s) with quotation marks?
  2. What data type am I using if I type a single digit number?
  3. What data type am I using if I type a decimal number?
  4. What data type am I using if I type either True or False?
  5. What does the int() instruction do?
  6. What does the str() instruction do?
  7. What does the float() instruction do?
  8. Why would you want to change one variable type into another?
  9. What is the difference between type casting and type conversion?
  10. Why might you want to type cast a variable rather than converting it?


Assessment Task (Homework)

Draw a timeline to show the development of the ‘first’ computer to our modern day computer. Don't use a computer to do this - by all means perform research using the Internet or a book but produce your timeline on a (long) piece of paper using traditional methods (pens, pencils and rulers)! The best efforts will go on display in your classroom.

Grading rubric

MASTER :  You have clearly performed considerable research into the development of the computer, charting the important milestones.  Your timeline is high quality and has clearly taken some time.  You are proud.
APPRENTICE You've found a timeline already on the internet and used it as a base for your timeline.  It's got some detail on it and it's carefully drawn.
NOVICE : You've used the computer to produce your timeline which consists mainly of image and copied information. You may have done it on paper but it's a little scruffy and you clearly haven't used a ruler.

Click to download revision cards
https://docs.google.com/document/d/166KF3hR0MOKScYkqPQ21Cj1o1cFK8A8V9Q9oANxfWVE/export?format=pdf
Remember to print them single sided

# Flash cards.png
Click to load key word list to help you make your own flash cards 

https://goo.gl/forms/1fT7GkmNt0YMaMJe2
Try to get 5/5!


Hungry for more?

The term Boolean comes from the name of the founder of the system of propositional logic, George Boole. He lived a long time ago, but if he lived today, he would more than likely have a social networking profile! Use the 'Social Network Template' to help you to complete this task. Instructions are included in the template.