w3resource

Understanding Python Literals: Booleans, Integers, and Floating-Point Numbers for PCEP-30-02 Exam ion

PCEP Certification Practice Test - Questions, Answers and Explanations

This comprehensive set of questions and explanations covers the fundamental topic of introducing literals and variables into code and using different numeral systems, providing a diverse set of interactions to enhance understanding and prepare for the PCEP-30-02 examination.

Question 1: Which of the following is a Boolean literal in Python?

  1. 1
  2. True
  3. "False"
  4. 0.0

Answer: B) True

Explanation: True and False are the Boolean literals in Python.

Question 2: Which of the following represents an integer literal in Python?

  1. 3.14
  2. "123"
  3. 101
  4. True

Answer: C) 101

Explanation: 101 is an integer literal, while 3.14 is a floating-point number, "123" is a string, and True is a Boolean.

Question 3: Which of the following are valid floating-point literals in Python? (Select all that apply)

  1. 3.14
  2. 10
  3. 0.001
  4. "3.14"

Answer: A) 3.14 C) 0.001

Explanation: 3.14 and 0.001 are floating-point literals, while 10 is an integer and "3.14" is a string.

Question 4: Match the following types of literals with their examples.

Literals Examples
Boolean 1. True
Integer 2. 3.14159
Floating-point 3. 42
String 4. "Hello, World!"

Answer:

  • Boolean -> True
  • Integer -> 42
  • Floating-point -> 3.14159
  • String -> "Hello, World!"

Explanation: Each literal type matches its respective example.

Question 5: Fill in the blanks: In Python, True and False are examples of _______ literals, while 3.14 and 0.001 are examples of _______ literals.

Answer: In Python, True and False are examples of Boolean literals, while 3.14 and 0.001 are examples of floating-point literals.

Explanation: True and False are Boolean literals, and 3.14 and 0.001 are floating-point literals.

Question 6: Arrange the following literals in the order of their types: Boolean, Integer, Floating-point, String.

Literals Order
42 1
True 2
"Hello" 3
3.14 4

Answer:

  • True (Boolean)
  • 42 (Integer)
  • 3.14 (Floating-point)
  • "Hello" (String)

Explanation: The order is based on the type of each literal.

Question 7: Fill in the code to assign the Boolean value False to a variable.

is_active = _______

Answer: False

Explanation: The variable is_active is assigned the Boolean value False.

Question 8: Insert the missing line of code to define a variable that holds the floating-point number 2.718.

e = _______
print(e)

Answer: 2.718

Explanation: The variable e is assigned the floating-point number 2.718

Question 9: What will be the output of the following code?

x = 10
y = 3.14
z = True
print(x, y, z)
 
  1. 10 3.14 True
  2. 10.0 3.14 1
  3. 10, 3.14, True
  4. 10 3.14 1

Answer: A) 10 3.14 True

Explanation: The variables x, y, and z hold the values 10, 3.14, and True respectively, and print outputs them with spaces in between.

Question 10: Fill in the code to assign the Boolean value True to a variable named is_active.

is_active = _______

Answer: True

Explanation: The variable is_active is assigned the Boolean value True.

Question 11: Arrange the following variable declarations in the order of their types: String, Integer, Floating-point, Boolean.

Variable Declarations Order
name = "Alice" 1
height = 5.7 2
age = 30 3
is_student = False 4

Answer:

  • name = "Alice" (String)
  • age = 30 (Integer)
  • height = 5.7 (Floating-point)
  • is_student = False (Boolean)

Explanation: The order is based on the type of each variable declaration.

Question 12: Fill in the blanks: In Python, a variable holding the value True is of type ________, while a variable holding the value 3.14 is of type ________.

Answer: In Python, a variable holding the value True is of type Boolean, while a variable holding the value 3.14 is of type floating-point.

Explanation: True is a Boolean value, and 3.14 is a floating-point value.

Question 13: What will be the output of the following code?

x = 5
y = 2.5
z = True
print(x, y, z)
  1. 5 2.5 True
  2. 5 2.5 1
  3. 5 2.5 0
  4. 5, 2.5, True

Answer: A) 5 2.5 True.

Explanation: The variables x, y, and z hold the values 5, 2.5, and True respectively, and print outputs them with spaces in between.

Question 14: Arrange the following variable assignments in the order of their types: Boolean, Integer, Floating-point.

Variable Assignments Order
pi = 3.14 1
is_valid = True 2
count = 10 3

Answer:

  • is_valid = True (Boolean)
  • count = 10 (Integer)
  • pi = 3.14 (Floating-point)

Explanation: The order is based on the type of each variable assignment.

Question 15: Which of the following are valid Boolean literals in Python? (Select all that apply).

  1. 1
  2. True
  3. flase
  4. False

Answer: B) True D) False

Explanation: True and False are the Boolean literals in Python. Note that false is incorrect as Python is case-sensitive.

Question 16: Insert the missing line of code to define a variable that holds the Boolean value True.

is_authenticated = _______
print(is_authenticated)

Answer: True

Explanation: The variable is_authenticated is assigned the Boolean value True.

Question 17: What will be the output of the following code?

a = 1.23
b = 4
c = False
print(a, b, c)

  1. 1 4 False
  2. 1.23 4 False
  3. 1.23 4 0
  4. 1 4 0

Answer: B) 1.23 4 False

Explanation: The variables a, b, and c hold the values 1.23, 4, and False respectively, and print outputs them with spaces in between.

Question 18: Which of the following are valid floating-point literals in Python? (Select all that apply)

  1. 5.0
  2. 10
  3. 2.71828
  4. "3.14"

Answer: A) 5.0 C) 2.71828

Explanation: 5.0 and 2.71828 are floating-point literals, while 10 is an integer and "3.14" is a string.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/python/certificate/literals-and-variables-boolean-integers-floating-point-numbers.php