
![[igCS] Variable and Data types](https://cf.quizizz.com/img/wayground/activity/activity-square.jpg?w=200&h=200)
[igCS] Variable and Data types
Presentation
•
Computers
•
9th Grade
•
Practice Problem
•
Easy
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")
Following output on screen:
"Hello"
Following output on screen:
Hello
Nothing happened
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)
Outputs:
"school"
Outputs:
School
Outputs:
"MAC"
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:
12_floor
twelve_floor
Twelve_floor
twelve floor
10
Multiple Choice
Which of the following is the best variable name, if we want to store someone's home address?
add
Address
home_address
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?
1092
-201
221.0
1.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?
bool
integer
char
string
19
Multiple Choice
What is the data type of the following variable:
p = True
int
float
bool
str
char
20
Multiple Choice
What is the data type of the following variable:
p = (1 > 0)
int
float
bool
str
char
21
Multiple Choice
Which of the following data types is not available in Python
int
float
bool
str
char
22
Multiple Choice
What is the data type of the following variable:
x = 10
int
float
bool
str
char
23
Multiple Choice
What is the data type of the following variable:
y = "10"
int
float
bool
str
char
[igCS] Variable and Data types
by Andy tsui
Show answer
Auto Play
Slide 1 / 23
SLIDE
Similar Resources on Wayground
19 questions
Magnetic and Optical Storage Devices
Presentation
•
9th Grade
20 questions
INFORMATIKA 9
Presentation
•
9th Grade
19 questions
Yr 11 - AQA GCSE Computer Science-Computer networks revision
Presentation
•
9th - 10th Grade
18 questions
Algebra - Introduction to Functions
Presentation
•
9th Grade
18 questions
TIK - KELAS 9 - PERTEMUAN 1
Presentation
•
9th Grade
19 questions
Solving Equations with Variables on Both Sides
Presentation
•
9th Grade
18 questions
For loops in python
Presentation
•
9th Grade
16 questions
9th Grade Biology
Presentation
•
9th Grade
Popular Resources on Wayground
24 questions
PBIS-HGMS Day 10
Quiz
•
6th - 8th Grade
10 questions
HCS SCI 03 Summer School Review 3
Quiz
•
3rd Grade
11 questions
Home Scope
Quiz
•
7th - 8th Grade
15 questions
HCS SCI 05 Summer School Assessment 3 Review
Quiz
•
5th Grade
35 questions
Lufkin Road Middle School Student Handbook & Policies Assessment
Quiz
•
7th Grade
18 questions
Geo 11.3 Area of Circles and Sectors
Quiz
•
9th - 11th Grade