

3rd Quarter Lesson of Python
Presentation
•
Computers
•
12th Grade
•
Practice Problem
•
Easy
Honey Fate Joy Villegas
Used 6+ times
FREE Resource
50 Slides • 81 Questions
1
Python Numbers
By Honey Fate Joy Villegas
2
Python Numbers
There are three numeric types in Python:
int
float
complex
​Variables of numeric types are created when you assign a value to them:
3
Python Numbers
Example
x = 1 # int
y = 2.8 # float
z = 1j # complex
4
Python Numbers
Example
print(type(x))
print(type(y))
print(type(z))
​To verify the type of any object in Python, use the type() function:
5
Python Numbers
Try your self
x = 3
y = 3.5
z = 3j
print(type(x))
print(type(y))
print(type(z))
6
Int
Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.
Example
Integers:
x = 1
y = 35656222554887711
z = -3255522
print(type(x))
print(type(y))
print(type(z))
7
Float
Float, or "floating point number" is a number, positive or negative, containing one or more decimals.
Example
Floats:
x = 1.10
y = 1.0
z = -35.59
print(type(x))
print(type(y))
print(type(z))
8
Float
Float, or "floating point number" is a number, positive or negative, containing one or more decimals.
Example
Floats:
x = 1.10
y = 1.0
z = -35.59
print(type(x))
print(type(y))
print(type(z))
Float can also be scientific numbers with an "e" to indicate the power of 10.
Example Floats:
x = 35e3
y = 12E4
z = -87.7e100
print(type(x))
print(type(y))
print(type(z))
9
Complex
Complex numbers are written with a "j" as the imaginary part:
x = 3+5j
y = 5j
z = -5j
print(type(x))
print(type(y))
print(type(z))
10
🧮 Debugging Activity: Python Number Types (int, float, and complex)
Instructions:
Copy and run the code below in your Python IDE or online compiler.
The program will not run properly or show incorrect results.
Identify the errors related to the use of number types (int, float, complex).
Fix the errors and run your corrected version until the program works as expected.
11
integer = 25.0
float_num = 10
complex_num = 3 + 2i
sum = integer + float_num
product = integer * complex_num
difference = integer - float_num
print("Integer value:", integer)
print("Float value:", float_num)
print("Complex number:", complex_num)
print("Sum:", sum)
print("Product:", product)
print("Difference:" difference)
12
Open Ended
integer = 25.0
float_num = 10
complex_num = 3 + 2i
sum = integer + float_num
product = integer * complex_num
difference = integer - float_num
print("Integer value:", integer)
print("Float value:", float_num)
print("Complex number:", complex_num)
print("Sum:", sum)
print("Product:", product)
print("Difference:" difference)
13
​✅ Corrected Code
integer = 25 # int
float_num = 10.0 # float
complex_num = 3 + 2j # complex numbers use 'j' in Python
sum_result = integer + float_num
product = integer * complex_num
difference = integer - float_num
print("Integer value:", integer)
print("Float value:", float_num)
print("Complex number:", complex_num)
print("Sum:", sum_result)
print("Product:", product)
print("Difference:", difference)
14
✅ Corrected Code
integer = 25 # int
float_num = 10.0 # float
complex_num = 3 + 2j # complex numbers use 'j' in Python
sum_result = integer + float_num
product = integer * complex_num
difference = integer - float_num
print("Integer value:", integer)
print("Float value:", float_num)
print("Complex number:", complex_num)
print("Sum:", sum_result)
print("Product:", product)
print("Difference:", difference)
Integer value: 25
Float value: 10.0
Complex number: (3+2j)
Sum: 35.0
Product: (75+50j)
Difference: 15.0
​💡 Expected Output:
15
16
17
Open Ended
Describe a scenario where you might need to convert the data type of a variable in a Python program.
18
Multiple Choice
Why is understanding type casting important for effective programming in Python?
It helps in converting data types and prevents errors.
It makes code run faster without any changes.
It allows skipping syntax rules in Python.
It is only useful for advanced programmers.
19
Example
x = int(1)
y = int(2.8)
z = int("3")
print(x)
print(y)
print(z)
20
Example
x = float(1)
y = float(2.8)
z = float("3")
w = float("4.2")
print(x)
print(y)
print(z)
print(w)
21
Example
x = str("s1") # x will be 's1'
y = str(2) # y will be '2'
z = str(3.0) # z will be '3.0'
22
23
Open Ended
Explain the difference between explicit casting and user-defined casting in Python.
24
Multiple Choice
Which of the following best describes implicit casting in Python?
Automatic type conversion by Python from smaller to larger data types.
Programmer-defined type conversion using functions like int(), float(), or str().
Custom casting methods created by users for specific conversion logic.
Conversion of data types only in user-defined classes.
25
26
27
Multiple Choice
Which function would you use to convert the string '10.5' to a numeric value suitable for precise financial calculations in Python?
float()
int()
str()
bool()
28
29
Fill in the Blank
The str() function is particularly useful for building ___ for user-facing messages or formatting data for display.
30
31
Multiple Select
Select all best practices to follow when performing casting in Python.
Always check types before casting
Handle exceptions using try-except blocks
Keep code readable and explicit
Avoid using built-in casting functions
32
33
Open Ended
How does mastering casting functions like int(), float(), and str() enhance data manipulation in Python?
34
Open Ended
What questions do you still have about type casting in Python, or is there any aspect you would like to explore further?
35
Multiple Choice
Why is understanding casting important in Python programming?
Because it helps convert data types and write effective code
Because it makes code run faster
Because it is required for all Python programs
Because it changes the syntax of Python
36
Multiple Choice
What will be the result of the following code:
print(int(35.88))
35
35.88
36
37
Multiple Choice
What will be the result of the following code:
print(float(35))
35
35.0
0.35
38
Multiple Choice
What will be the result of the following code:
print(str(35.82))
35
35.8
35.82
39
Performance Task
Task Description
You will be given a Python script (see below) that uses type casting (e.g., int(), float(), str()), but it contains multiple bugs (both syntax errors and logical errors). Your job is to debug the script so that it runs correctly and produces the expected output. Then, add comments explaining why each bug happened, why your fix works, and what the casting rules are in that context (based on the tutorial).
40
a = "1234"
b = 56.78
# 1) convert a to an integer, store in ai
ai = int(a)
# 2) convert b to a string, store in bs
bs = b.str()
# 3) convert ai to a float, store in af
af = float(ai)
# 4) attempt to convert a non-numeric string to integer
c = "hello"
ci = int(c)
print("a (string) =", a)
print("ai (int) =", ai)
print("b (float) =", b)
print("bs (string) =", bs)
print("af (float) =", af)
print("c (string) =", c)
print("ci (int) =", ci)
41
Expected Behavior / Output
After your fixes, the script should:
Convert "1234" to integer → ai = 1234
Convert the float 56.78 to string → bs = "56.78"
Convert ai to a float → af = 1234.0
For "hello", you should handle the fact that this string cannot be converted to integer — either by catching the error and printing a meaningful message, or by converting only what’s valid.
42
Open Ended
a = "1234"
b = 56.78
# 1) convert a to an integer, store in ai
ai = int(a)
# 2) convert b to a string, store in bs
bs = b.str()
# 3) convert ai to a float, store in af
af = float(ai)
# 4) attempt to convert a non-numeric string to integer
c = "hello"
ci = int(c)
print("a (string) =", a)
print("ai (int) =", ai)
print("b (float) =", b)
print("bs (string) =", bs)
print("af (float) =", af)
print("c (string) =", c)
print("ci (int) =", ci)
43
a (string) = 1234
ai (int) = 1234
b (float) = 56.78
bs (string) = 56.78
af (float) = 1234.0
c (string) = hello
ci (int) = Could not convert "hello" to an integer
Output
44
Python Strings
Strings
Strings in python are surrounded by either single quotation marks, or double quotation marks.
'hello' is the same as "hello".
You can display a string literal with the print() function:
45
Python Strings
Strings
Example
print("Hello")
print('Hello')
46
Python Strings
Quotes Inside Quotes
You can use quotes inside a string, as long as they don't match the quotes surrounding the string:
​Example print("It's alright") print("He is called 'Johnny'") print('He is called "Johnny"')
47
Python Strings
Assign String to a Variable
Assigning a string to a variable is done with the variable name followed by an equal sign and the string:
Example
a = "Hello"
print(a)
48
Python Strings
Multiline Strings
You can assign a multiline string to a variable by using three quotes:
Example
You can use three double quotes:
a = """Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua."""
print(a)
Or three single quotes:
Example
a = '''Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.'''
print(a)
49
Python Strings
Looping Through a String
Since strings are arrays, we can loop through the characters in a string, with a for loop.
Example
Loop through the letters in the word "banana":
for x in "banana":
print(x)
51
Python Strings
Check String
To check if a certain phrase or character is present in a string, we can use the keyword in.
Example
Check if "free" is present in the following text:
txt = "The best things in life are free!"
print("free" in txt)
52
Python Strings
Check String
Use it in an if statement:
Example
Print only if "free" is present:
txt = "The best things in life are free!"
if "free" in txt:
print("Yes, 'free' is present.")
53
Python Strings
Check if NOT
To check if a certain phrase or character is NOT present in a string, we can use the keyword not in.
Example
Check if "expensive" is NOT present in the following text:
txt = "The best things in life are free!"
print("expensive" not in txt)
54
Python Strings
Check if NOT
Use it in an if statement:
Example
print only if "expensive" is NOT present:
txt = "The best things in life are free!"
if "expensive" not in txt:
print("No, 'expensive' is NOT present.")
55
Multiple Choice
What will be the result of the following code:
Wel
c
Welcome Welcome Welcome
56
Fill in the Blank
What will be the result of the following code:Use the len function to print the length of the string.
57
Fill in the Blank
Get the first character of the string txt.
58
Drag and Drop
if 'free'
print('Yes, free is present in the text.')
59
Open Ended
x = "Hello world!
print(x)
print("The length of the string is: " len(x))
print("Uppercase: ", x.upper)
print("Lowercase: " x.lower())
print("First letter:", x[0]
print("Last letter:", x[-1])
sentence = " Python programming is fun "
print(sentence.strip)
print("Replaced text:", sentence.replace("fun", "awesome")
60
Python Booleans
61
Python Booleans
Example
print(10 > 9)
print(10 == 9)
print(10 < 9)
65
Python Booleans
Functions can Return a Boolean
You can create functions that returns a Boolean Value:
Example
Print the answer of a function:
def myFunction() :
return True
print(myFunction())
66
Python Booleans
Functions can Return a Boolean
You can execute code based on the Boolean answer of a function:
Example
Print "YES!" if the function returns True, otherwise print "NO!":
def myFunction() :
return True
if myFunction():
print("YES!")
else:
print("NO!")
67
Python Booleans
Python also has many built-in functions that return a boolean value, like the isinstance() function, which can be used to determine if an object is of a certain data type:
Example
Check if an object is an integer or not:
x = 200
print(isinstance(x, int))
68
Exercise
69
Multiple Choice
What will be the result of the following syntax:
print(5 > 3)?
True
False
5 > 3
70
Fill in the Blank
What Boolean value would print (print(10 > 9))?
71
Fill in the Blank
What Boolean value would print (print(10 == 9))?
72
Fill in the Blank
What Boolean value would print (print(10 < 9))?
73
Fill in the Blank
What Boolean value would print (print(10 < 9))?
74
Fill in the Blank
What Boolean value would print (print(bool("abc")))?
75
Fill in the Blank
What Boolean value would print (print(bool(0)))?
76
🐞 Debugging Activity: Python Booleans
Instructions
Each code snippet below has a bug related to Boolean logic (and, or, not, comparisons, or conditionals).
For each one:
Predict what the code should do
Find the bug
Fix it
Test your fix
77
Open Ended
Comparison vs Assignment
Task:
Why does this cause an error? What symbol should be used instead?
78
Open Ended
Boolean Logic Error
Task:
Why does this cause an error? What symbol should be used instead?
79
Open Ended
String Comparison Bug
Task:
Why does this cause an error? What symbol should be used instead?
80
Open Ended
Boolean vs String Confusion
Task:
Why does this cause an error? What symbol should be used instead?
81
82
Multiple Choice
Which of the following is NOT a numeric data type in Python?
int
complex
float
string
83
Multiple Choice
What type of data is the value 10?
float
complex
int
str
84
Multiple Choice
What type of data is the value 2.5?
Int
bool
float
complex
85
Multiple Choice
Which of the following represents a complex number?
3
2j
3.5
"3"
86
Multiple Choice
Which function is used to know the type of a variable?
typeof()
check()
type()
var()
87
Multiple Choice
If x = 5 and y = 2.0, what type is x + y?
Int
complex
float
bool
88
Multiple Choice
What is the result type of 10 / 2?
int
complex
float
bool
89
Multiple Choice
Which operator gives the remainder?
//
%
**
+
90
Multiple Choice
Which operator is used for floor division?
/
%
//
**
91
Multiple Choice
What is the type of 5j?
int
float
complex
string
92
Multiple Choice
What is the result of this expression? int(8.9) + int(3.1)
12
10
11
9
93
Multiple Choice
What is the value of x after executing this code? x = 7 // 2 + 3 ** 2
12
9
10
8
94
Multiple Choice
What is printed by the following code? a = 3 b = 2 c = a ** b * b print(c)
12
36
18
8
95
Multiple Choice
A student is writing a program to compute the average score of 3 quizzes. The scores are 85, 90, and 88. To ensure the result shows decimal values if needed, which expression should be used?
(85 + 90 + 88) // 3
int(85 + 90 + 88) / 3
(85 + 90 + 88) / 3
float(85 + 90 + 88) // 3
96
Multiple Choice
A game developer needs to divide 17 coins equally among 4 players and determine how many coins are left. Which Python operator should be used to get the remaining coins?
/
%
//
**
97
Multiple Choice
A programmer stores a distance as 12.7 kilometers but needs it as a whole number for display. Which statement will convert it to 12?
float(12.7)
str(12.7)
int(12.7)
round(12.7)
98
Multiple Choice
A robotics program uses complex numbers to represent movement. If the program sets: position = 3 + 4j Which part of this value represents the imaginary component?
3
j
4
4j
99
Multiple Choice
Which function converts a value into an integer?
int()
str()
float()
bool()
100
Multiple Choice
What is the result of float("5")?
"5"
5.0
5
error
101
Multiple Choice
How do you convert 10 into a string?
int(10)
str(10)
float(10)
bool(10)
102
Multiple Choice
What will int("25") return?
"25"
25.0
25
error
103
Multiple Choice
Which will cause an error?
int("4")
int("abc")
float("4.5")
str(10)
104
Multiple Choice
What is the result of bool(0)?
True
0
False
None
105
Multiple Choice
What is the result of str(3.5)?
3.5
3
"3.5"
error
106
Multiple Choice
Which function converts a value into a float?
int()
str()
float()
bool()
107
Multiple Choice
What does int(9.9) return?
9
9.9
10
error
108
Multiple Choice
What is the output of the following code? x = "12" y = 3 print(int(x) + y)
"123"
123
15
Error
109
Multiple Choice
What will this code print? print(type(float("7")))
110
Multiple Choice
What is the result of this expression? int(5.9) + int("3")
9
7
8
Error
111
Multiple Choice
What is the output? print(bool("0"))
True
0
False
Error
112
Multiple Choice
What is printed? x = float(4) y = int(x) print(y)
4.0
"4"
4
Error
113
Multiple Choice
A student receives a user input "25" from a form and needs to perform arithmetic with it. Which statement correctly converts it into a number?
int("25")
str("25")
float("25")
bool("25")
114
Multiple Choice
A programmer stores a price as 10 but wants to display it as "10.0" in the output. Which code should be used?
str(10)
str(float(10))
float(10)
int(10.0)
115
Multiple Choice
A teacher wants to check if a user typed something in an input box. The input is stored as a string. Which statement can be used to check if it is empty?
int(input)
float(input)
bool(input)
str(input)
116
Multiple Choice
A game program reads the value "0" from a file and needs to determine if it represents a true or false condition. Which conversion should be used?
int("0")
str("0")
bool("0")
float("0")
117
Multiple Choice
Which data type is used for text?
int
str
float
bool
118
Multiple Choice
Which symbol is used to define a string?
''
both A and B
""
none
119
Multiple Choice
What is the result of len("Python")?
4
6
5
7
120
Multiple Choice
Which index refers to the first character?
0
-1
1
2
121
Multiple Choice
What is "Hi" + "There"?
HiThere
Hi+There
Hi There
Error
122
Multiple Choice
Which checks if a word is inside a string?
in
has
is
find
123
Multiple Choice
What does "Hello"[1] return?
H
l
e
o
124
Multiple Choice
Which of the following creates a multi-line string?
''' ... '''
both A and B
""" """
" "
125
Multiple Choice
Can strings be changed after they are created?
yes
no
none
both A and B
126
Multiple Choice
What is the output of the following code? x = "Python" print(x[1:4])
Pyt
Tho
yth
hon
127
Multiple Choice
What will be printed? text = "Hello" print(text[-1])
H
l
e
o
128
Multiple Choice
What is the result of this code? s = "abc" print(s * 2 + "d")
abcd
abcabcd
abcabc
abcdabc
129
Multiple Choice
What does the following expression return? "Python".replace("t", "T")
Python
PYTHON
PyThon
PythoT
130
Multiple Choice
What will this code print? msg = "Hi" msg = msg + "!" msg = msg * 2 print(msg)
Hi!
Hi!!
Hi!Hi!
Hi!2
131
Multiple Choice
What will be the output of the following code? value = "100" print(value + " is a number")
100 is a number100
100 is a number
100is a number
Error
Python Numbers
By Honey Fate Joy Villegas
Show answer
Auto Play
Slide 1 / 131
SLIDE
Similar Resources on Wayground
112 questions
LAC Session, Dec 1, 2021
Lesson
•
Professional Development
112 questions
Hbl alles
Lesson
•
University
121 questions
Why Big Data Matters?
Lesson
•
University
127 questions
Desenvolvendo Jogos 2D com Unity 2j
Lesson
•
11th Grade
130 questions
Entrep - 314
Lesson
•
University
128 questions
Gr 7 bjc review 2025
Lesson
•
9th Grade
117 questions
第四課 python編程入門
Lesson
•
9th - 12th Grade
114 questions
gambar teknik
Lesson
•
10th Grade
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
10 questions
Probability Practice
Quiz
•
4th Grade
15 questions
Probability on Number LIne
Quiz
•
4th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
6 questions
Appropriate Chromebook Usage
Lesson
•
7th Grade
10 questions
Greek Bases tele and phon
Quiz
•
6th - 8th Grade