Search Header Logo
3rd Quarter Lesson of Python

3rd Quarter Lesson of Python

Assessment

Presentation

Computers

12th Grade

Practice Problem

Easy

Created by

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:

  1. Copy and run the code below in your Python IDE or online compiler.

  2. The program will not run properly or show incorrect results.

  3. Identify the errors related to the use of number types (int, float, complex).

  4. 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

media

16

media

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?

1

It helps in converting data types and prevents errors.

2

It makes code run faster without any changes.

3

It allows skipping syntax rules in Python.

4

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

media

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?

1

Automatic type conversion by Python from smaller to larger data types.

2

Programmer-defined type conversion using functions like int(), float(), or str().

3

Custom casting methods created by users for specific conversion logic.

4

Conversion of data types only in user-defined classes.

25

media

26

media

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?

1

float()

2

int()

3

str()

4

bool()

28

media

29

Fill in the Blank

The str() function is particularly useful for building ___ for user-facing messages or formatting data for display.

30

media

31

Multiple Select

Select all best practices to follow when performing casting in Python.

1

Always check types before casting

2

Handle exceptions using try-except blocks

3

Keep code readable and explicit

4

Avoid using built-in casting functions

32

media

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?

1

Because it helps convert data types and write effective code

2

Because it makes code run faster

3

Because it is required for all Python programs

4

Because it changes the syntax of Python

36

Multiple Choice

What will be the result of the following code:
print(int(35.88))

1

35

2

35.88

3

36

37

Multiple Choice

What will be the result of the following code:
print(float(35))

1

35

2

35.0

3

0.35

38

Multiple Choice

What will be the result of the following code:
print(str(35.82))

1

35

2

35.8

3

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

# CastingScript.py

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:

  1. Convert "1234" to integer → ai = 1234

  2. Convert the float 56.78 to string → bs = "56.78"

  3. Convert ai to a float → af = 1234.0

  4. 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

# CastingScript.py

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)

50

Python Strings

String Length

To get the length of a string, use the len() function.

Example

The len() function returns the length of a string:

a = "Hello, World!"
print(len(a))

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

Question image

What will be the result of the following code:

1


Wel

2

c

3

Welcome Welcome Welcome

56

Fill in the Blank

Question image

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

Question image

Get the first character of the string txt.

[
]

58

Drag and Drop

txt = 'The best things in life are free!'
if 'free' ​
txt:​
  print('Yes, free is present in the text.') ​ ​ ​ ​ ​

Drag these tiles and drop them in the correct blank above
contains
present
match
in

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

Booleans represent one of two values: True or False.

In programming you often need to know if an expression is True or False.


You can evaluate any expression in Python, and get one of two answers, True or False.


When you compare two values, the expression is evaluated and Python returns the Boolean answer:

61

Python Booleans

Example

print(10 > 9)
print(10 == 9)
print(10 < 9)

62

Python Booleans

When you run a condition in an if statement, Python returns True or False:

Example

Print a message based on whether the condition is True or False:

a = 200
b =
33

if b > a:
 
print("b is greater than a")
else:
 
print("b is not greater than a")

63

Python Booleans

Evaluate Values and Variables

The bool() function allows you to evaluate any value, and give you True or False in return,

Example

Evaluate a string and a number:

print(bool("Hello"))
print(bool(15))

64

Python Booleans

Most Values are True

Almost any value is evaluated to True if it has some sort of content.

Any string is True, except empty strings.

Any number is True, except 0.

Any list, tuple, set, and dictionary are True, except empty ones.

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

media

Exercise

69

Multiple Choice

What will be the result of the following syntax:
print(5 > 3)?

1

True


2

False

3

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:

  1. Predict what the code should do

  2. Find the bug

  3. Fix it

  4. Test your fix

77

Open Ended

Question image

Comparison vs Assignment

Task:
Why does this cause an error? What symbol should be used instead?

78

Open Ended

Question image

Boolean Logic Error

Task:
Why does this cause an error? What symbol should be used instead?

79

Open Ended

Question image

String Comparison Bug

Task:
Why does this cause an error? What symbol should be used instead?

80

Open Ended

Question image

Boolean vs String Confusion

Task:
Why does this cause an error? What symbol should be used instead?

81

media

82

Multiple Choice

Which of the following is NOT a numeric data type in Python?

1

int

2

complex

3

float

4

string

83

Multiple Choice

What type of data is the value 10?

1

float

2

complex

3

int

4

str

84

Multiple Choice

What type of data is the value 2.5?

1

Int

2

bool

3

float

4

complex

85

Multiple Choice

Which of the following represents a complex number?

1

3

2

2j

3

3.5

4

"3"

86

Multiple Choice

Which function is used to know the type of a variable?

1

typeof()

2

check()

3

type()

4

var()

87

Multiple Choice

If x = 5 and y = 2.0, what type is x + y?

1

Int

2

complex

3

float

4

bool

88

Multiple Choice

What is the result type of 10 / 2?

1

int

2

complex

3

float

4

bool

89

Multiple Choice

Which operator gives the remainder?

1

//

2

%

3

**

4

+

90

Multiple Choice

Which operator is used for floor division?

1

/

2

%

3

//

4

**

91

Multiple Choice

What is the type of 5j?

1

int

2

float

3

complex

4

string

92

Multiple Choice

What is the result of this expression? int(8.9) + int(3.1)

1

12

2

10

3

11

4

9

93

Multiple Choice

What is the value of x after executing this code? x = 7 // 2 + 3 ** 2

1

12

2

9

3

10

4

8

94

Multiple Choice

What is printed by the following code? a = 3 b = 2 c = a ** b * b print(c)

1

12

2

36

3

18

4

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?

1

(85 + 90 + 88) // 3

2

int(85 + 90 + 88) / 3

3

(85 + 90 + 88) / 3

4

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?

1

/

2

%

3

//

4

**

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?

1

float(12.7)

2

str(12.7)

3

int(12.7)

4

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?

1

3

2

j

3

4

4

4j

99

Multiple Choice

Which function converts a value into an integer?

1

int()

2

str()

3

float()

4

bool()

100

Multiple Choice

What is the result of float("5")?

1

"5"

2

5.0

3

5

4

error

101

Multiple Choice

How do you convert 10 into a string?

1

int(10)

2

str(10)

3

float(10)

4

bool(10)

102

Multiple Choice

What will int("25") return?

1

"25"

2

25.0

3

25

4

error

103

Multiple Choice

Which will cause an error?

1

int("4")

2

int("abc")

3

float("4.5")

4

str(10)

104

Multiple Choice

What is the result of bool(0)?

1

True

2

0

3

False

4

None

105

Multiple Choice

What is the result of str(3.5)?

1

3.5

2

3

3

"3.5"

4

error

106

Multiple Choice

Which function converts a value into a float?

1

int()

2

str()

3

float()

4

bool()

107

Multiple Choice

What does int(9.9) return?

1

9

2

9.9

3

10

4

error

108

Multiple Choice

What is the output of the following code? x = "12" y = 3 print(int(x) + y)

1

"123"

2

123

3

15

4

Error

109

Multiple Choice

What will this code print? print(type(float("7")))

1

2

3

4

110

Multiple Choice

What is the result of this expression? int(5.9) + int("3")

1

9

2

7

3

8

4

Error

111

Multiple Choice

What is the output? print(bool("0"))

1

True

2

0

3

False

4

Error

112

Multiple Choice

What is printed? x = float(4) y = int(x) print(y)

1

4.0

2

"4"

3

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?

1

int("25")

2

str("25")

3

float("25")

4

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?

1

str(10)

2

str(float(10))

3

float(10)

4

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?

1

int(input)

2

float(input)

3

bool(input)

4

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?

1

int("0")

2

str("0")

3

bool("0")

4

float("0")

117

Multiple Choice

Which data type is used for text?

1

int

2

str

3

float

4

bool

118

Multiple Choice

Which symbol is used to define a string?

1

''

2

both A and B

3

""

4

none

119

Multiple Choice

What is the result of len("Python")?

1

4

2

6

3

5

4

7

120

Multiple Choice

Which index refers to the first character?

1

0

2

-1

3

1

4

2

121

Multiple Choice

What is "Hi" + "There"?

1

HiThere

2

Hi+There

3

Hi There

4

Error

122

Multiple Choice

Which checks if a word is inside a string?

1

in

2

has

3

is

4

find

123

Multiple Choice

What does "Hello"[1] return?

1

H

2

l

3

e

4

o

124

Multiple Choice

Which of the following creates a multi-line string?

1

''' ... '''

2

both A and B

3

""" """

4

" "

125

Multiple Choice

Can strings be changed after they are created?

1

yes

2

no

3

none

4

both A and B

126

Multiple Choice

What is the output of the following code? x = "Python" print(x[1:4])

1

Pyt

2

Tho

3

yth

4

hon

127

Multiple Choice

What will be printed? text = "Hello" print(text[-1])

1

H

2

l

3

e

4

o

128

Multiple Choice

What is the result of this code? s = "abc" print(s * 2 + "d")

1

abcd

2

abcabcd

3

abcabc

4

abcdabc

129

Multiple Choice

What does the following expression return? "Python".replace("t", "T")

1

Python

2

PYTHON

3

PyThon

4

PythoT

130

Multiple Choice

What will this code print? msg = "Hi" msg = msg + "!" msg = msg * 2 print(msg)

1

Hi!

2

Hi!!

3

Hi!Hi!

4

Hi!2

131

Multiple Choice

What will be the output of the following code? value = "100" print(value + " is a number")

1

100 is a number100

2

100 is a number

3

100is a number

4

Error

Python Numbers

By Honey Fate Joy Villegas

Show answer

Auto Play

Slide 1 / 131

SLIDE