Search Header Logo
[igCS] Variable and Data types

[igCS] Variable and Data types

Assessment

Presentation

Computers

9th Grade

Practice Problem

Easy

Created by

Andy tsui

Used 5+ times

FREE Resource

11 Slides • 12 Questions

1

[igCS] Variable and Data types

by Andy tsui

2

​Objectives

  • Declare and use variables and constants

  • Understand and use the basic data types

3

Multiple Choice

What will be produced by the following python statement:

print("Hello")

1

Following output on screen:

"Hello"

2

Following output on screen:

Hello

3

Nothing happened

4

Computer say hello to you

4

​Activity

In REPL, create a new PYTHON project, name it variables

​# put the following in main.py

​name = "your name"

​print(name)

5

​Variable

  • Variable is like a container/box which we can put value/data inside

  • ​Each variable can store ONE piece of data only at anytime

​grade = "F3"

  • The ​= sign in the above statement is called "assignment", which means we store a value to a variable

6

Retrieving values

  • ​To access the value of variable, simply replace value with the variable name:

# the following will output the value of grade

print(grade)

7

Multiple Choice

What will be the result of following code:

school = "MAC"

print(school)

1

Outputs:

"school"

2

Outputs:

School

3

Outputs:

"MAC"

4

Outputs:

MAC

8

​Variable naming conventions

  • You can give (almost) any name to a variable, but:​

    • Meaningful and relevant

      • ​e.g. class_number, firstname

    • Keep it explanatory but concise

  • ​Variable cannot start with number and not containing symbols (except _) or space

    • ​So we use _ to replace space, e.g. average_score

  • ​All variables in lowercase letters

    • although capital letter is acceptable, but this is the conventions used by the Python community

9

Multiple Select

Which of the followings are invalid variable names:

1

12_floor

2

twelve_floor

3

Twelve_floor

4

twelve floor

10

Multiple Choice

Which of the following is the best variable name, if we want to store someone's home address?

1

add

2

Address

3

home_address

4

1_address

11

Open Ended

Suggest a good variable name to store class number of a student.

12

​Data Types

  • ​Each piece of data has it's "data type"

  • ​To help the computer to correctly handle and process data

13

​String

  • ​String means sequence of characters

    • ​Python called "str"

  • ​To indicate the data is string, we must put string in a pair of " "

​# inside print, we are actually giving a string # for print to output:

​print("Hello world")

14

​Numbers

  • ​Two major types of numbers:

    • ​Integer - integer is called int in Python

    • ​Real - Python called it float

15

Multiple Select

Which of the following is an integer?

1

1092

2

-201

3

221.0

4

1.5

5

"100"

16

​Character (Char)

  • ​Char is one single character

  • ​We use 'x' (pair of single quote) to indicate a value is character

  • ​There is NO char in python. Python simply use treat character as string

17

​Boolean (Logical True/False)

  • ​Boolean (bool in Python) consisted of two possible values only

    • ​True

    • ​False (Note: the first letter is capital in Python)

18

Multiple Choice

Which of the following data types contains two possible values only?

1

bool

2

integer

3

char

4

string

19

Multiple Choice

What is the data type of the following variable:

p = True

1

int

2

float

3

bool

4

str

5

char

20

Multiple Choice

What is the data type of the following variable:

p = (1 > 0)

1

int

2

float

3

bool

4

str

5

char

21

Multiple Choice

Which of the following data types is not available in Python

1

int

2

float

3

bool

4

str

5

char

22

Multiple Choice

What is the data type of the following variable:

x = 10

1

int

2

float

3

bool

4

str

5

char

23

Multiple Choice

What is the data type of the following variable:

y = "10"

1

int

2

float

3

bool

4

str

5

char

[igCS] Variable and Data types

by Andy tsui

Show answer

Auto Play

Slide 1 / 23

SLIDE