CCNA Data Types, Variables, Basic I/O and Operators Questions

74 of 196 questions · Page 2/3 · Data Types, Variables, Basic I/O and Operators · Answers revealed

76
MCQeasy

Which of the following expressions evaluates to False?

A.2 != 1
B.10 == 10
C.3 >= 4
D.5 < 10
AnswerC

3 is not >= 4, so false.

Why this answer

Option C (3 >= 4) evaluates to False because the 'greater than or equal to' operator (>=) returns True only if the left operand is greater than or equal to the right operand. Since 3 is neither greater than nor equal to 4, the expression is False.

Exam trap

Python Institute often tests whether candidates confuse the direction of comparison operators (e.g., mistaking >= for <=) or forget that >= includes equality, leading them to incorrectly assume 3 >= 4 is True.

How to eliminate wrong answers

Option A is wrong because 2 != 1 uses the inequality operator (!=) and returns True since 2 is not equal to 1. Option B is wrong because 10 == 10 uses the equality operator (==) and returns True since both operands are equal. Option D is wrong because 5 < 10 uses the less-than operator (<) and returns True since 5 is indeed less than 10.

77
Multi-Selecthard

Which TWO operators in Python yield an integer result when applied to two integers?

Select 2 answers
A.//
B.**
C.%
D.*
E./
AnswersA, C

Floor division always returns an integer for ints.

Why this answer

The floor division operator (//) always returns an integer result when both operands are integers, discarding any fractional part. For example, 7 // 2 yields 3, not 3.5. This is because floor division performs integer division and truncates toward negative infinity, ensuring the result type is int when both inputs are int.

Exam trap

Python Institute often tests the distinction between / (always returns float) and // (returns int for int operands), and the trap here is that candidates mistakenly think the modulo operator (%) returns a float, but it actually returns an integer when both operands are integers, and they may also incorrectly believe that multiplication (*) always returns an integer (which it does, but the exam deliberately omits it from the correct answers to test knowledge of // and % specifically).

78
MCQhard

What is the output of print(type(3 + 4.5))?

A.<class 'int'>
B.<class 'complex'>
C.<class 'float'>
D.<class 'str'>
AnswerC

Correct: the result is float.

Why this answer

In Python, when you add an integer (3) and a float (4.5), implicit type conversion (coercion) occurs: the integer is promoted to a float to avoid data loss. The result is 7.5, which is a float. Therefore, type(7.5) returns <class 'float'>.

Exam trap

Python Institute often tests the misconception that integer + float yields an integer, or that the type() function returns the string 'int' or 'float' rather than the actual class object.

How to eliminate wrong answers

Option A is wrong because the result of adding an int and a float is not an int; Python does not truncate or round the result to an integer. Option B is wrong because the result is not a complex number; complex numbers require an imaginary part (e.g., 3+4j). Option D is wrong because the result is a numeric value, not a string; the print function outputs the type object as a string representation, but the underlying type is float.

79
MCQeasy

A user enters '42' at an input prompt. After executing x = input(), what is the type of x?

A.float
B.str
C.bool
D.int
AnswerB

Correct: input() returns a string

Why this answer

The `input()` function in Python always returns the user's input as a string, regardless of whether the input looks like a number. When the user enters '42', it is captured as the string '42', so the type of `x` is `str`. This is because `input()` does not perform any implicit type conversion.

Exam trap

The trap here is that candidates assume `input()` automatically converts numeric-looking input to an integer or float, because many other languages (like C++ with `cin`) do so, but Python's `input()` always returns a string.

How to eliminate wrong answers

Option A is wrong because `float` would only be the type if the code explicitly converted the input using `float(x)`, but `input()` alone returns a string. Option C is wrong because `bool` is never the default return type of `input()`; a boolean would require explicit conversion or a specific condition. Option D is wrong because `int` would require explicit conversion via `int(x)`; `input()` does not automatically parse numeric strings into integers.

80
MCQmedium

What is the output of the code?

A.<class 'str'>
B.<class 'float'>
C.<class 'int'>
D.<class 'bool'>
AnswerB

Division yields float.

Why this answer

The expression `3 / 2` performs true division in Python, which always returns a float even if both operands are integers. The result is `1.5`, and `type(1.5)` returns `<class 'float'>`. Therefore, option B is correct.

Exam trap

Python Institute often tests the distinction between true division (`/`) and floor division (`//`), and the trap here is that candidates mistakenly think dividing two integers always yields an integer, forgetting that Python 3's `/` always returns a float.

How to eliminate wrong answers

Option A is wrong because `3 / 2` does not produce a string; it produces a numeric value, and `type()` returns a class object, not a string literal. Option C is wrong because true division (`/`) never returns an int in Python 3; it always returns a float, even when the division is exact (e.g., `4 / 2` returns `2.0`). Option D is wrong because the result of `3 / 2` is not a Boolean; it is a numeric float, and `type()` would never return `<class 'bool'>` for a division operation.

81
MCQeasy

A developer writes a script to calculate the average of three numbers: avg = (a + b + c) / 3. If a=5, b=10, c=15, what is the data type of avg?

A.float
B.bool
C.int
D.str
AnswerA

Division returns a float.

Why this answer

In Python, the division operator (/) always returns a float, even when dividing integers that result in a whole number. Here, (5 + 10 + 15) / 3 equals 30 / 3, which yields 10.0, a float. Therefore, the data type of avg is float.

Exam trap

Python Institute often tests the distinction between / (true division, returns float) and // (floor division, returns int) to trap candidates who assume integer division returns an integer.

How to eliminate wrong answers

Option B is wrong because bool is a data type for Boolean values (True/False), and the result of arithmetic division cannot be a bool. Option C is wrong because int would only be the type if integer division (//) were used, but the standard division operator (/) always produces a float in Python 3. Option D is wrong because str is a string data type, and the result of numeric division is never a string unless explicitly converted.

82
MCQmedium

A program needs to check if a number is both positive and even. Which expression correctly implements this?

A.if num > 0 or num % 2 == 0:
B.if num > 0 and num % 2 == 0:
C.if num > 0 & num % 2 == 0:
D.if num > 0 and % 2 == 0:
AnswerB

Correct: both conditions must be true.

Why this answer

Option B is correct because it uses the logical `and` operator to combine two conditions: `num > 0` (checks if the number is positive) and `num % 2 == 0` (checks if the number is even). Both conditions must be true for the overall expression to be true, which correctly implements the requirement of checking if a number is both positive and even.

Exam trap

Python Institute often tests the distinction between logical operators (`and`, `or`) and bitwise operators (`&`, `|`), as well as the correct syntax for the modulo operator, to catch candidates who confuse these concepts.

How to eliminate wrong answers

Option A is wrong because it uses the `or` operator, which returns true if either condition is true, meaning it would accept a positive odd number or a negative even number, not requiring both conditions. Option C is wrong because `&` is the bitwise AND operator, not a logical operator; it performs bitwise comparison on integers, which can produce unexpected boolean results and is not the correct way to combine conditions in an `if` statement. Option D is wrong because it has a syntax error: the modulo operator `%` is missing its left operand (it should be `num % 2 == 0`), making the expression invalid.

83
MCQeasy

What is the result of bool(0) in Python?

A.0
B.None
C.True
D.False
AnswerD

Correct; 0 is falsy.

Why this answer

The bool() function in Python converts any value to a Boolean. The integer 0 is considered a falsy value, so bool(0) returns False. This is because Python defines 0, None, empty collections, and False itself as falsy.

Exam trap

Python Institute often tests the misconception that bool(0) returns 0 or None, exploiting candidates who confuse the integer value 0 with the Boolean False, or who think that only the literal False keyword is falsy.

How to eliminate wrong answers

Option A is wrong because bool(0) does not return the integer 0; it returns a Boolean value, not an integer. Option B is wrong because bool(0) does not return None; None is a separate falsy value but is not the result of converting 0 to Boolean. Option C is wrong because 0 is not truthy; only non-zero integers evaluate to True when passed to bool().

84
MCQhard

Which expression evaluates to False?

A.3 > 4
B.3 <= 3
C.3 == 3
D.3 != 2
AnswerA

3 is not greater than 4, so False.

Why this answer

Option A is correct because the expression `3 > 4` evaluates to `False` in Python, as 3 is not greater than 4. All other options evaluate to `True` due to the correct application of comparison operators: `<=`, `==`, and `!=`.

Exam trap

Python Institute often tests whether candidates confuse the assignment operator `=` with the equality operator `==`, or mistakenly think that `<=` requires strict inequality, leading them to incorrectly evaluate `3 <= 3` as `False`.

How to eliminate wrong answers

Option B is wrong because `3 <= 3` evaluates to `True` — the `<=` operator returns `True` when the left operand is less than or equal to the right operand, and here they are equal. Option C is wrong because `3 == 3` evaluates to `True` — the `==` operator checks for value equality, and both integers are identical. Option D is wrong because `3 != 2` evaluates to `True` — the `!=` operator returns `True` when the operands are not equal, and 3 is indeed not equal to 2.

85
MCQmedium

A company needs to calculate the average of three test scores entered by a user. The scores are integers. The programmer writes the following code: s1 = input("Enter score 1: ") s2 = input("Enter score 2: ") s3 = input("Enter score 3: ") avg = (s1 + s2 + s3) / 3 print("Average:", avg) When run, the output is incorrect. What is the most likely cause?

A.The division by 3 will cause a ZeroDivisionError because 3 is not a float.
B.The division operator / always returns an integer, but the sum is not an integer.
C.The variable names s1, s2, s3 are not allowed because they start with a letter.
D.The input() function returns strings, so concatenation occurs instead of addition.
AnswerD

input() returns a string, so using + on strings concatenates them.

Why this answer

Option D is correct because the `input()` function in Python always returns a string, even when the user types numbers. The `+` operator on strings performs concatenation (e.g., '5' + '3' + '2' becomes '532'), not numeric addition. Dividing the concatenated string by 3 then causes a `TypeError` (or produces an incorrect result if the string is implicitly converted), so the average calculation fails.

Exam trap

Python Institute often tests the misconception that `input()` returns a numeric type, leading candidates to overlook the need for explicit type conversion before arithmetic operations.

How to eliminate wrong answers

Option A is wrong because dividing by an integer literal like 3 is perfectly valid; Python allows division by integers, and a `ZeroDivisionError` only occurs when dividing by zero, not by a non-zero integer. Option B is wrong because the `/` operator in Python 3 always returns a float, not an integer, and the issue is not about the return type of division. Option C is wrong because variable names starting with a letter (like s1, s2, s3) are perfectly allowed in Python; identifiers must start with a letter or underscore, so these names are valid.

86
MCQmedium

A programmer writes: result = 'Py' * 2 + 'thon'. What is the value of result?

A.'Py2thon'
B.'Python'
C.'Pyththon'
D.'PyPy'
AnswerB

Correct: 'Py'*2 = 'PyPy', plus 'thon' = 'Python'

Why this answer

Option B is correct because in Python, the * operator on a string repeats it, and the + operator concatenates strings. 'Py' * 2 produces 'PyPy', then 'PyPy' + 'thon' results in 'Python'. This follows Python's operator precedence where * has higher precedence than +, so the multiplication is evaluated first.

Exam trap

Cisco often tests the misconception that the * operator concatenates the string with the numeric value as a string (e.g., 'Py' * 2 becomes 'Py2'), or that it only repeats the last character, leading candidates to choose option A or C.

How to eliminate wrong answers

Option A is wrong because it incorrectly assumes that the * operator concatenates with a numeric representation, producing 'Py2thon', but Python's string repetition does not insert the number as a string. Option C is wrong because it suggests the repetition applies only to the last character, yielding 'Pyththon', but * repeats the entire string 'Py', not just the 'y'. Option D is wrong because it shows only the result of 'Py' * 2 as 'PyPy', ignoring the concatenation with 'thon'.

87
MCQmedium

Which of the following variable names is NOT valid in Python?

A.My_Var
B._myVar
C.2nd_place
D.myVar2
AnswerC

Invalid; starts with a digit.

Why this answer

Option C is correct because Python variable names cannot begin with a digit. The name '2nd_place' starts with '2', which violates Python's identifier naming rules. Valid variable names must start with a letter (a-z, A-Z) or an underscore (_), followed by letters, digits, or underscores.

Exam trap

Python Institute often tests the rule that variable names cannot start with a digit, and the trap here is that candidates may focus on the underscore or mixed case and overlook the leading digit, mistakenly thinking '2nd_place' is acceptable because it contains letters and underscores.

How to eliminate wrong answers

Option A is wrong because 'My_Var' starts with a letter and contains only letters and underscores, which is perfectly valid in Python. Option B is wrong because '_myVar' starts with an underscore, which is allowed and commonly used for internal or private variables. Option D is wrong because 'myVar2' starts with a letter and contains letters and digits, which is valid as digits are allowed after the first character.

88
MCQmedium

A developer runs the command and sees the output. Which statement about the data type is correct?

A.3.14 is a decimal.Decimal type.
B.3.14 is a float, but Python also treats it as a double.
C.3.14 is a float in Python.
D.3.14 is a string.
AnswerC

Correct; the type is float.

Why this answer

Option C is correct because in Python, numeric literals with a decimal point, such as 3.14, are always interpreted as the built-in float type. Python does not have a separate 'double' type; its float is implemented as a C double (64-bit IEEE 754), but the language itself refers to it as float. This is a fundamental rule of Python's data type system.

Exam trap

Cisco often tests the misconception that Python has separate 'float' and 'double' types, similar to languages like C or Java, when in fact Python's float is always double-precision and there is no distinct double type.

How to eliminate wrong answers

Option A is wrong because decimal.Decimal is a separate type from the decimal module, not a built-in literal type; 3.14 is not automatically a Decimal. Option B is wrong because Python does not have a distinct 'double' type — it uses a single float type, which is implemented as a double-precision floating-point number under the hood, but the language name is simply 'float'. Option D is wrong because 3.14 is not enclosed in quotes, so it is a numeric literal, not a string.

89
Multi-Selecteasy

Which TWO of the following are Python membership operators?

Select 2 answers
A.not
B.not in
C.in
D.is
E.and
AnswersB, C

Membership operator.

Why this answer

Option B is correct because 'not in' is a Python membership operator that returns True if a value is not found in a sequence (like a list, tuple, or string). Option C is correct because 'in' is the complementary membership operator that returns True if a value is found in a sequence. Both are used to test membership in iterable objects.

Exam trap

Python Institute often tests the distinction between membership operators ('in', 'not in') and identity operators ('is', 'is not'), as candidates frequently confuse 'is' with 'in' or mistake 'not' as a standalone membership operator when it must be paired with 'in'.

90
MCQeasy

Which of the following is a valid variable name in Python?

A.my-var
B.2nd_place
C._count
D.class
AnswerC

Underscore is allowed at start.

Why this answer

Option C (_count) is correct because in Python, variable names can start with an underscore, and underscores are allowed anywhere in the name. The name _count follows all Python identifier rules: it starts with a letter or underscore, contains only letters, digits, or underscores, and is not a reserved keyword.

Exam trap

Python Institute often tests the rule that hyphens are not allowed in variable names, leading candidates to mistakenly think my-var is valid because it resembles common naming in other languages or file systems.

How to eliminate wrong answers

Option A is wrong because my-var contains a hyphen (-), which is not allowed in Python identifiers; only underscores are permitted as separators. Option B is wrong because 2nd_place starts with a digit, which violates Python's rule that identifiers must begin with a letter or underscore. Option D is wrong because class is a reserved keyword in Python and cannot be used as a variable name.

91
MCQeasy

What is the correct way to read a floating-point number from user input and store it in a variable?

A.x = input(float())
B.x = input() as float
C.x = float(input())
D.x = input().float()
AnswerC

Reads input as string, then converts to float.

Why this answer

Option C is correct because `float(input())` first reads the user input as a string via `input()`, then converts that string to a floating-point number using the `float()` function. This is the standard and only valid way in Python to obtain a float from console input, as `input()` always returns a string.

Exam trap

The trap here is that candidates often confuse the order of operations, thinking they can apply a type conversion method directly on the input string (like `.float()`) or use non-existent syntax like `as float`, instead of wrapping the `input()` call with the `float()` function.

How to eliminate wrong answers

Option A is wrong because `input(float())` attempts to call `float()` with no argument (which returns 0.0) and then passes that float as the prompt argument to `input()`, not converting the user's input. Option B is wrong because `x = input() as float` is not valid Python syntax; the `as` keyword is used only in `with` statements and exception handling, not for type conversion. Option D is wrong because `x = input().float()` tries to call a method named `float()` on the string returned by `input()`, but strings have no such method, causing an AttributeError.

92
MCQmedium

A developer runs the script and enters 'Alice' and '25'. What does it print?

A.Alice is 25.0 years old.
B.Alice is Alice is 25 years old.
C.Alice is 25 years old. (with age as integer)
D.Alice is 25 years old.
AnswerD

Correct: string concatenation.

Why this answer

Option D is correct because the input() function returns strings, and the print() function with commas inserts spaces between arguments. The age '25' is printed as a string, not an integer, so no decimal point appears. The output is 'Alice is 25 years old.'

Exam trap

Python Institute often tests the fact that input() returns a string, leading candidates to incorrectly assume numeric input is automatically converted to an integer or float, or that print() with commas adds no spaces.

How to eliminate wrong answers

Option A is wrong because it shows '25.0', which would only occur if age were converted to a float (e.g., float(age)), but the script does not perform such conversion. Option B is wrong because it repeats 'Alice is' twice, which would require duplicate print arguments or string concatenation errors not present in the code. Option C is wrong because it claims age is an integer, but input() always returns a string; the output shows '25' as a string, not an integer type.

93
MCQhard

A data analyst uses Python to process a CSV file containing sales data. The file has columns: 'Product', 'Price', 'Quantity'. The analyst writes a script to compute total sales: sum of Price * Quantity for each row. The code reads each row as a list of strings. The analyst uses: total = 0; for row in reader: total += row['Price'] * row['Quantity']; print(total). The script raises a TypeError. What is the best fix?

A.Convert Price and Quantity to float before multiplication.
B.Change the loop to for i in range(len(reader)): total += reader[i][1] * reader[i][2].
C.Use integer multiplication and then convert to float.
D.Use float(row[1]) * float(row[2]) instead of row['Price'] * row['Quantity'].
AnswerA

Correct: convert strings to floats.

Why this answer

Option A is correct because the script attempts to multiply two strings (row['Price'] and row['Quantity']), which raises a TypeError. Converting both values to float before multiplication ensures numeric arithmetic. This directly addresses the type mismatch in the original code.

Exam trap

Python Institute often tests the distinction between string repetition (valid) and string multiplication of two strings (invalid), leading candidates to overlook the need for explicit type conversion.

How to eliminate wrong answers

Option B is wrong because it still uses string indices (reader[i][1] and reader[i][2]) without conversion, so multiplication of strings still raises a TypeError. Option C is wrong because integer multiplication would fail if the data contains decimal values (e.g., '19.99'), and converting to float afterward does not fix the initial type error. Option D is wrong because it uses numeric indices (row[1], row[2]) instead of the column names 'Price' and 'Quantity', which would cause a KeyError if the CSV reader uses DictReader, or would access the wrong columns if the order differs.

94
Drag & Dropmedium

Order the steps to define and call a function in Python.

Drag steps to the numbered slots on the right, or tap a step then tap a slot.

Steps
Order

Why this order

Function definition starts with def, then the body, parameters are optional, and calling the function executes it.

95
MCQeasy

What is the output when the user enters 25?

A.Error
B.2525
C.25
D.50
AnswerB

Correct. String replication.

Why this answer

When the user enters 25, the input() function returns the string "25". The print() function then concatenates the string "25" with itself using the + operator, resulting in "2525". This is because the + operator performs string concatenation when both operands are strings, not numeric addition.

Exam trap

Python Institute often tests the distinction between string concatenation and numeric addition, exploiting the fact that input() returns a string, so candidates mistakenly assume the + operator will perform arithmetic.

How to eliminate wrong answers

Option A is wrong because no error occurs; input() always returns a string, and concatenating two identical strings is a valid operation. Option C is wrong because it assumes the output is a single "25", but the code explicitly prints the concatenation of two copies of the input string. Option D is wrong because it assumes numeric addition (25+25=50), but the + operator concatenates strings, not numbers, since input() returns a string.

96
Multi-Selectmedium

Which TWO of the following expressions evaluate to True?

Select 2 answers
A.bool('')
B.bool([])
C.bool(1)
D.bool('False')
E.bool(0)
AnswersC, D

Non-zero integer is True.

Why this answer

Option C is correct because `bool(1)` converts the integer 1 to a Boolean, and in Python any non-zero numeric value is considered truthy, so `bool(1)` returns `True`. Option D is correct because `bool('False')` converts the non-empty string `'False'` to a Boolean; in Python, any non-empty string is truthy, regardless of its textual content, so it returns `True`.

Exam trap

The trap here is that candidates often mistakenly think the string `'False'` is falsy because it looks like the Boolean `False`, but Python evaluates truthiness based on the object's type and content, not its string representation.

97
MCQhard

What is the result of the expression: print(2 ** 3 ** 2) ?

A.512
B.256
C.64
D.128
AnswerA

2**(3**2) = 2**9 = 512.

Why this answer

The expression `2 ** 3 ** 2` uses the exponentiation operator `**`, which in Python is right-associative. This means it is evaluated as `2 ** (3 ** 2)`, not `(2 ** 3) ** 2`. First, `3 ** 2` equals 9, then `2 ** 9` equals 512.

Therefore, option A is correct.

Exam trap

The trap here is that many candidates assume exponentiation is left-associative like most other arithmetic operators, leading them to compute `(2 ** 3) ** 2 = 64` instead of the correct right-associative `2 ** (3 ** 2) = 512`.

How to eliminate wrong answers

Option B (256) is wrong because it would result from `(2 ** 3) ** 2` (i.e., 8 ** 2 = 64) and then incorrectly doubling, not from the correct right-associative evaluation. Option C (64) is wrong because it represents the result of `(2 ** 3) ** 2` (8 squared), which is the left-associative misinterpretation of the expression. Option D (128) is wrong because it would come from `2 ** 7` (a miscalculation of the exponent), not from the correct `2 ** 9`.

98
MCQmedium

A program calculates BMI. User inputs weight and height as strings. Which line correctly converts to float?

A.weight = float(input)
B.weight = input().float()
C.weight = float(input())
D.weight = input(float())
AnswerC

Correct; input() returns string, float() converts.

Why this answer

Option C is correct because `float(input())` first reads the user's input as a string via `input()`, then converts that string to a floating-point number using the `float()` function. This is the standard Python pattern for converting user input to a numeric type.

Exam trap

Python Institute often tests the distinction between calling a function (`float(input())`) versus referencing it (`float(input)`) or chaining a non-existent method (`input().float()`), exploiting the common confusion that methods and functions are interchangeable.

How to eliminate wrong answers

Option A is wrong because `float(input)` passes the function object `input` itself, not the result of calling it, causing a TypeError. Option B is wrong because `input().float()` attempts to call a method named `float` on a string object, but strings have no such method; the correct approach is to use the built-in `float()` function. Option D is wrong because `input(float())` tries to call `input()` with a float argument (the result of `float()`), which is meaningless and will raise a TypeError since `input()` expects an optional string prompt, not a number.

99
Multi-Selectmedium

Which three of the following are Python arithmetic operators? (Choose three.)

Select 3 answers
A.+
B.|
C.-
D.&
E.*
AnswersA, C, E

Addition operator

Why this answer

Option A is correct because the plus sign (+) is a standard Python arithmetic operator used for addition. It performs numeric addition when both operands are numbers, and also supports string concatenation, but its primary role in arithmetic contexts is addition.

Exam trap

Python Institute often tests the distinction between arithmetic operators and bitwise operators, trapping candidates who mistake the vertical bar or ampersand for arithmetic symbols due to their visual similarity to plus or multiplication signs.

100
MCQeasy

A programmer writes: x = 5; y = "10"; z = x + y. What will happen?

A.Prints error but continues execution
B.Prints 510
C.TypeError: unsupported operand type(s) for +: 'int' and 'str'
D.Prints 15
AnswerC

Correct; Python raises TypeError for mismatched types.

Why this answer

Option C is correct because Python does not implicitly convert between incompatible types for the '+' operator. When an integer (int) and a string (str) are used with '+', Python raises a TypeError, as it cannot decide whether to perform arithmetic addition or string concatenation without explicit conversion.

Exam trap

Python Institute often tests the misconception that Python will automatically convert types to make the operation work, either by treating the integer as a string (concatenation) or the string as a number (addition), when in fact Python raises a TypeError for mixed-type '+' operations.

How to eliminate wrong answers

Option A is wrong because Python does not print an error and continue execution; it raises an unhandled TypeError that stops the program unless caught with a try/except block. Option B is wrong because it assumes Python will automatically convert the integer to a string and concatenate them as '510', but Python does not perform implicit type coercion for '+' between int and str. Option D is wrong because it assumes Python will convert the string '10' to an integer and perform numeric addition to get 15, but Python does not implicitly convert strings to integers for arithmetic operations.

101
MCQmedium

What is the output of the code?

A.<class 'str'>
B.<class 'int'>
C.<class 'float'>
D.<class 'bool'>
AnswerC

Correct. Division yields a float.

Why this answer

The code uses the `type()` function to determine the data type of the result of the expression `10 / 3`. In Python 3, the `/` operator always performs true division, which returns a floating-point number even if the operands are integers. Therefore, `10 / 3` evaluates to `3.3333333333333335` (a float), and `type()` returns `<class 'float'>`.

Option C is correct.

Exam trap

Python Institute often tests the distinction between `/` (true division) and `//` (floor division) in Python 3, and the trap here is that candidates mistakenly think integer division with `/` yields an integer, confusing it with Python 2 behavior or the `//` operator.

How to eliminate wrong answers

Option A is wrong because the result of `10 / 3` is not a string; the `/` operator does not produce a string type. Option B is wrong because true division (`/`) in Python 3 never returns an integer; it always returns a float, even when the division is exact (e.g., `4 / 2` returns `2.0`). Option D is wrong because the result is not a Boolean; division does not yield a `bool` type, and the expression is not a comparison or logical operation.

102
MCQhard

Given 'a = 10; b = 3; c = a // b; d = a % b', what is the value of c + d?

A.4
B.5
C.7
D.6
AnswerA

Floor division gives 3, modulo gives 1, sum is 4.

Why this answer

In Python, the // operator performs floor division, so a // b = 10 // 3 = 3. The % operator returns the remainder, so a % b = 10 % 3 = 1. Therefore, c + d = 3 + 1 = 4, making option A correct.

Exam trap

Python Institute often tests the distinction between floor division (//) and true division (/), and the trap here is that candidates may mistakenly use regular division (10 / 3 ≈ 3.33) and then add the remainder incorrectly, or forget that // and % are complementary operations that together reconstruct the original dividend.

How to eliminate wrong answers

Option B (5) is wrong because it might result from incorrectly using regular division (10 / 3 ≈ 3.33) and rounding up, or from adding the quotient (3) and remainder (1) incorrectly as 4, not 5. Option C (7) is wrong because it could come from adding the quotient (3) and the divisor (3) plus the remainder (1), or from miscomputing the remainder as 4 (10 % 3 = 1, not 4). Option D (6) is wrong because it might arise from adding the quotient (3) and the divisor (3) together, ignoring the remainder, or from a miscalculation of floor division as 2.

103
MCQeasy

Which of the following is a valid Python variable name?

A.2var
B._var
C.my-var
D.var$name
AnswerB

Underscores are allowed and commonly used.

Why this answer

Option B (_var) is correct because Python variable names must start with a letter or an underscore, and can contain letters, digits, or underscores. The underscore is a valid starting character, making _var a legal identifier.

Exam trap

Python Institute often tests the misconception that hyphens or special characters like '$' are allowed in variable names, or that digits can start a name, because candidates confuse Python's rules with those of other languages like JavaScript or PHP.

How to eliminate wrong answers

Option A is wrong because Python variable names cannot begin with a digit; '2var' starts with '2', which violates the syntax rule. Option C is wrong because the hyphen '-' is not allowed in Python identifiers; only underscores, letters, and digits are permitted. Option D is wrong because the dollar sign '$' is not a valid character in Python variable names; identifiers are limited to alphanumeric characters and underscores.

104
MCQeasy

A data analyst needs to read two integers from the user and compute their average as a float. The current code: a = int(input()) b = int(input()) avg = a + b / 2 print(avg) The output is always incorrect when a=5 and b=7 (expected 6.0, actual 8.5). The analyst cannot identify the bug. What is the root cause and correct fix?

A.The input function is not converting correctly; use float(input()) instead.
B.The print function is rounding the result; use print("{:.1f}".format(avg)).
C.The addition and division have wrong operator precedence; use parentheses: (a + b) / 2.
D.The division operator / always returns an integer; use // instead.
AnswerC

Without parentheses, division happens first.

Why this answer

Option C is correct because in Python, the division operator `/` has higher precedence than addition `+`, so `a + b / 2` is evaluated as `a + (b / 2)`, not `(a + b) / 2`. For a=5 and b=7, this computes `5 + (7 / 2) = 5 + 3.5 = 8.5` instead of the expected `(5 + 7) / 2 = 12 / 2 = 6.0`. Adding parentheses around `a + b` forces the addition to occur first, yielding the correct average as a float.

Exam trap

Python Institute often tests operator precedence by presenting a simple arithmetic expression without parentheses, leading candidates to overlook the order of operations and incorrectly blame input conversion or output formatting.

How to eliminate wrong answers

Option A is wrong because the issue is not about input conversion; `int(input())` correctly reads integers, and using `float(input())` would not fix the operator precedence bug. Option B is wrong because the print function does not round the result; the actual computed value is 8.5, not 6.0, so formatting the output would still show 8.5. Option D is wrong because the `/` operator in Python 3 always returns a float (e.g., 7/2 = 3.5), and using `//` would perform floor division, yielding an integer result (e.g., 12//2 = 6) but would break for odd sums (e.g., 5+6=11, 11//2=5, not 5.5), so it is not the correct fix.

105
Multi-Selectmedium

Which TWO of the following Python data types are mutable?

Select 2 answers
A.list
B.str
C.tuple
D.int
E.dict
AnswersA, E

Lists can be modified in place.

Why this answer

Option A is correct because lists in Python are mutable, meaning their elements can be changed, added, or removed after creation. This is a fundamental property of the list type, which supports operations like append(), extend(), and item assignment.

Exam trap

Python Institute often tests the misconception that strings or tuples are mutable because they support indexing and slicing, but candidates must remember that these operations return new objects rather than modifying the original.

106
MCQeasy

A developer wants to store a person's age. Which of these variable names is invalid?

A._age
B.3rd_age
C.Age
D.age_3
AnswerB

Variable cannot start with a number.

Why this answer

In Python, variable names must start with a letter or an underscore, not a digit. Option B (`3rd_age`) begins with a digit, which violates Python's identifier naming rules and will raise a `SyntaxError` if used in code.

Exam trap

Python Institute often tests the rule that variable names cannot start with a digit, tricking candidates who focus on case sensitivity or underscores instead of the initial character restriction.

How to eliminate wrong answers

Option A is wrong because `_age` starts with an underscore, which is allowed in Python variable names. Option C is wrong because `Age` starts with a letter and is case-sensitive but valid. Option D is wrong because `age_3` starts with a letter and contains an underscore and digit, both permitted after the first character.

107
MCQeasy

A junior developer is writing a script to calculate the total cost of items in a shopping cart. The script uses variables item_price (float) and quantity (int). The code is: item_price = 2.5 quantity = 3 total = item_price * quantity print("Total: " + total) When run, this code raises a TypeError. The developer is confused because the multiplication seems correct. What is the most likely issue and the correct fix?

A.The variable total is being overwritten by the print statement; use a different variable name.
B.The multiplication should be written as int(item_price) * quantity to ensure integer result.
C.The variable names are too descriptive; rename them to a and b to avoid confusion.
D.The print function cannot concatenate a string with a float; convert total to string using str(total).
AnswerD

Concatenation requires both operands to be strings.

Why this answer

Option D is correct because the `print` function in Python expects all arguments to be strings when using the `+` operator for concatenation. The variable `total` is a float (result of multiplying a float by an int), and Python does not implicitly convert it to a string. The error is a `TypeError: can only concatenate str (not 'float') to str`.

The fix is to explicitly convert `total` to a string using `str(total)` before concatenation.

Exam trap

Python Institute often tests the distinction between arithmetic operations (which work across numeric types) and string concatenation (which requires explicit type conversion), trapping candidates who assume Python will automatically convert a float to a string when using the `+` operator.

How to eliminate wrong answers

Option A is wrong because the `print` statement does not overwrite the variable `total`; it only reads its value. The error is a type mismatch in concatenation, not a variable naming issue. Option B is wrong because converting `item_price` to an integer would lose the decimal precision (2.5 becomes 2), and the multiplication result would be incorrect for a shopping cart total.

The error is not about integer vs. float multiplication; it's about string concatenation. Option C is wrong because variable names being descriptive is a best practice, not a cause of errors. Renaming them to `a` and `b` would not fix the `TypeError` and would reduce code readability.

108
MCQmedium

You are a data analyst at a retail company. You have a list of sales figures stored as strings in a list: sales = ['100', '200', '300']. You need to calculate the total sum. A colleague suggests using: total = sum(sales). However, this raises a TypeError because sum() requires numeric values. Which approach should you take to correctly calculate the total as an integer?

A.Use total = sum(sales) and catch TypeError
B.Use total = sum(int(s) for s in sales)
C.Use total = sum(map(int, sales))
D.Use total = 0; for s in sales: total += s
AnswerB, C

Generator expression converts each to int and sums.

Why this answer

Option B is correct because it uses a generator expression to convert each string element in the `sales` list to an integer via `int(s)` before passing the resulting integers to `sum()`. The `sum()` function requires numeric operands; passing strings directly causes a `TypeError`. By converting to integers first, the total is correctly computed as an integer.

Exam trap

Python Institute often tests the misconception that `sum()` can implicitly convert strings to numbers, or that catching an exception is a valid workaround, when in fact explicit conversion via `int()` is required.

How to eliminate wrong answers

Option A is wrong because catching a `TypeError` does not fix the underlying problem—the strings are still not converted to numbers, so the sum would still fail or require additional handling. Option D is wrong because `total += s` attempts to add a string to an integer, which raises a `TypeError` due to incompatible types; the loop must convert each `s` to an integer first.

109
Multi-Selecteasy

Which of the following are valid Python variable names? (Choose two.)

Select 2 answers
A.for
B.data_1
C._count
D.2nd_place
E.my-var
AnswersB, C

Letters, digits, and underscores are allowed, and the name does not start with a digit.

Why this answer

Option B (data_1) is correct because Python variable names can contain letters, digits, and underscores, but must not start with a digit. 'data_1' starts with a letter and includes an underscore and digit, all of which are allowed.

Exam trap

Cisco often tests the distinction between hyphens (which are not allowed) and underscores (which are allowed), and the rule that keywords like 'for' cannot be used as variable names, even though they look like valid identifiers.

110
MCQhard

Which of the following is an invalid variable name in Python?

A._myVar
B.myVar
C.my-var
D.my_var
AnswerC

Invalid; hyphens are not allowed in identifiers.

Why this answer

Option C is correct because 'my-var' contains a hyphen, which is not allowed in Python variable names. Python identifiers can only include letters, digits, and underscores, and cannot start with a digit. The hyphen is interpreted as a minus operator, making 'my-var' a syntax error.

Exam trap

Cisco often tests the misconception that hyphens are acceptable in variable names because they appear in other languages (like JavaScript object keys) or in file names, but Python strictly prohibits them in identifiers.

How to eliminate wrong answers

Option A is wrong because '_myVar' is a valid variable name; underscores are allowed and commonly used for private or internal variables. Option B is wrong because 'myVar' follows Python naming rules (letters and underscores, no special characters). Option D is wrong because 'my_var' is valid; underscores are permitted and often used in snake_case naming conventions.

111
Multi-Selecteasy

Which TWO data types are immutable in Python?

Select 2 answers
A.str
B.set
C.list
D.dict
E.int
AnswersA, E

Immutable. Strings cannot be modified in-place.

Why this answer

Option A is correct because strings (str) are immutable in Python, meaning once a string object is created, its content cannot be changed; any operation that appears to modify a string actually creates a new string object. Option E is correct because integers (int) are also immutable; when you perform arithmetic on an integer, a new integer object is created rather than modifying the original.

Exam trap

Cisco often tests the misconception that 'immutable' means the variable cannot be reassigned, but immutability refers to the object itself, not the variable binding; candidates may incorrectly think lists or dicts are immutable because they can reassign the variable.

112
MCQmedium

A developer writes: print(10 * '5'). What is the output?

A.10
B.50
C.5
D.5555555555
AnswerD

String repetition.

Why this answer

In Python, the multiplication operator (*) when used with a string and an integer performs string repetition. The expression 10 * '5' repeats the string '5' ten times, resulting in the string '5555555555'. The print() function then outputs this concatenated string without quotes.

Exam trap

The trap here is that candidates often confuse the string repetition operator with arithmetic multiplication, leading them to mistakenly compute 10 * 5 = 50 instead of recognizing that the operand is a string literal.

How to eliminate wrong answers

Option A is wrong because it incorrectly assumes the result is the integer 10, ignoring that the string '5' is repeated, not converted to an integer. Option B is wrong because it treats the string '5' as the integer 5 and performs arithmetic multiplication (10 * 5 = 50), which is a common confusion between string repetition and numeric multiplication. Option C is wrong because it suggests only a single '5' is output, misunderstanding that the operator repeats the string multiple times.

113
MCQhard

A developer is working on a project that requires handling large numbers. They write: x = 10000000000 y = 3.0 z = x / y print(int(z)) The output is 3333333333. However, the developer expected 3333333333 (same). But they suspect that integer division might be better. They try: x = 10000000000 y = 3 z = x // y print(z) Output: 3333333333. Both give same. Now they test with negative numbers: x = -10 y = 3 z1 = x / y z2 = x // y print(z1, z2) The output is -3.3333333333333335 and -4. The developer is confused why z2 is -4 instead of -3. Which of the following explains the behavior?

A.The division operator / rounds toward zero, while // rounds toward negative infinity.
B.Truncation division always rounds toward zero, so -10 // 3 should be -3, but Python has a bug.
C.Floor division always rounds down toward negative infinity, so -10 // 3 = -4 because -3.33 floor is -4.
D.The result depends on the types; using float y yields different result.
AnswerC

Floor division rounds to the nearest integer less than or equal to the exact quotient.

Why this answer

Option C is correct because Python's floor division (`//`) always rounds down toward negative infinity, not toward zero. For `-10 // 3`, the exact result is approximately -3.333..., and the floor (largest integer ≤ the value) is -4, not -3. This is consistent with the mathematical definition of floor division used in Python.

Exam trap

Python Institute often tests the distinction between truncation toward zero (common in many languages) and floor division toward negative infinity (Python's behavior), trapping candidates who assume `//` always rounds toward zero.

How to eliminate wrong answers

Option A is wrong because the `/` operator performs true division and returns a float, not rounding toward zero; the rounding behavior described is for truncation, not Python's `/`. Option B is wrong because Python does not have a bug; `//` is explicitly defined as floor division, not truncation toward zero, so `-10 // 3` correctly yields -4. Option D is wrong because the type of `y` (float vs int) does not change the floor division behavior for `//`; the result type may differ, but the rounding rule remains floor toward negative infinity.

114
Multi-Selecthard

Which THREE of the following are built-in Python data types? (Choose three.)

Select 3 answers
A.str
B.boolean
C.int
D.list
E.array
AnswersA, C, D

Built-in: string type.

Why this answer

Option A is correct because `str` is a built-in Python data type used to represent sequences of Unicode characters. It is one of the fundamental immutable sequence types in Python, defined in the language specification and available without importing any module.

Exam trap

Python Institute often tests the distinction between built-in types and types available only through modules, so candidates mistakenly choose `array` or `boolean` because they sound familiar, but Python uses `bool` and requires importing `array`.

115
MCQhard

Refer to the exhibit. What will happen when this code is executed?

A.Prints 10.5
B.Prints 10
C.Raises TypeError
D.Raises ValueError
AnswerD

int() expects integer representation.

Why this answer

The code attempts to convert the string '10.5' to an integer using int(). Since '10.5' contains a decimal point, it is not a valid integer literal; int() cannot parse it and raises a ValueError. The correct approach would be to first convert to float (float('10.5')) and then to int if needed.

Exam trap

Python Institute often tests the distinction between ValueError and TypeError, trapping candidates who think a decimal string causes a TypeError when it actually raises a ValueError because the string is not a valid integer literal.

How to eliminate wrong answers

Option A is wrong because the code does not print 10.5; int('10.5') raises an exception before any print occurs. Option B is wrong because int('10.5') does not truncate or round the string to 10; it raises a ValueError instead. Option C is wrong because TypeError occurs when an operation is applied to an inappropriate type (e.g., adding string and int), but here the issue is that the string '10.5' is not a valid integer representation, which is a ValueError.

116
MCQeasy

A student writes the following code to calculate the average of two numbers: ```python num1 = input("Enter first number: ") num2 = input("Enter second number: ") avg = (num1 + num2) / 2 print("Average:", avg) ``` When executed, the code raises a TypeError. What is the most likely cause?

A.The division operator '/' is not allowed for integers
B.The input() function returns a string, not a number, so arithmetic operations are invalid without conversion
C.The addition operator '+' cannot be used with strings
D.The variable names num1 and num2 are reserved keywords
AnswerB

Correct. input() returns a string; arithmetic requires numeric conversion.

Why this answer

The `input()` function in Python always returns a string, regardless of what the user types. Attempting to use the `+` operator on two strings performs concatenation, not numeric addition, and then dividing a concatenated string by an integer with `/` raises a `TypeError` because the `/` operator is not defined for strings. To fix this, the inputs must be explicitly converted to numbers using `int()` or `float()` before arithmetic operations.

Exam trap

Python Institute often tests the misconception that `input()` returns a numeric type when the user types digits, leading candidates to overlook the need for explicit type conversion with `int()` or `float()`.

How to eliminate wrong answers

Option A is wrong because the division operator '/' is fully allowed for integers in Python and performs true division, returning a float. Option C is wrong because the addition operator '+' can be used with strings for concatenation; the error arises from the subsequent division, not the addition itself. Option D is wrong because 'num1' and 'num2' are not reserved keywords in Python; they are valid variable names.

117
MCQeasy

A developer writes the following code: x = 5; y = x; x = 10. What are the values of x and y after execution?

A.x = 10, y = 5
B.x = 5, y = 10
C.x = 5, y = 5
D.x = 10, y = 10
AnswerA

x is reassigned to 10, y still holds the original 5

Why this answer

In Python, integers are immutable, and the assignment `y = x` copies the reference to the integer object 5, not the variable itself. When `x = 10` is executed, it binds the name `x` to a new integer object 10, while `y` still references the original object 5. Thus, after execution, `x` is 10 and `y` is 5.

Exam trap

Python Institute often tests the misconception that `y = x` creates a persistent link between variables, leading candidates to incorrectly assume `y` changes when `x` is reassigned.

How to eliminate wrong answers

Option B is wrong because it suggests `x = 5` and `y = 10`, which would require `y` to be reassigned after `x` changed, but no such reassignment occurs. Option C is wrong because it implies `x` remains 5, ignoring the explicit reassignment `x = 10`. Option D is wrong because it assumes `y` is updated when `x` changes, which would only happen if integers were mutable or if `y` were a reference to `x` itself, but Python integers are immutable and assignment creates a new binding.

118
Multi-Selecthard

Which TWO of the following expressions evaluate to 0? (Select two.)

Select 2 answers
A.False * 1
B.5 // 2 * 2
C.True == 0
D.int(0.5)
E.5 % 2
AnswersA, D

False is 0, product is 0.

Why this answer

Option A is correct because in Python, `False` is treated as 0 in arithmetic contexts, so `False * 1` evaluates to `0 * 1 = 0`. Option D is correct because `int(0.5)` truncates the decimal part toward zero, resulting in the integer 0.

Exam trap

Python Institute often tests the distinction between boolean values in arithmetic versus comparison contexts, tricking candidates into thinking `True == 0` evaluates to the integer 0 rather than the boolean `False`.

119
MCQeasy

A program prompts a user for their age using input(). Which line of code correctly stores the age as an integer?

A.age = str(input("Enter age: "))
B.age = float(input("Enter age: "))
C.age = int(input("Enter age: "))
D.age = input("Enter age: ")
AnswerC

Correctly converts input string to integer.

Why this answer

Option C is correct because the `int()` function explicitly converts the string returned by `input()` into an integer, which is required for storing a numeric age value. The `input()` function always returns a string in Python, so without conversion, arithmetic operations would fail or produce unexpected results.

Exam trap

The trap here is that candidates often forget `input()` returns a string and assume the user's typed digits are automatically stored as a number, leading them to pick option D without any conversion.

How to eliminate wrong answers

Option A is wrong because `str()` converts the input to a string, but `input()` already returns a string, so this adds unnecessary conversion and does not produce an integer. Option B is wrong because `float()` converts the input to a floating-point number, which is not appropriate for an age that should be a whole number and may introduce decimal precision issues. Option D is wrong because it stores the raw string from `input()` without any type conversion, so the variable remains a string and cannot be used directly in integer arithmetic.

120
MCQhard

A script calculates total cost: price = 49.95, quantity = 3, tax_rate = 0.08. The developer writes: total = price * quantity * (1 + tax_rate). The result is printed as 161.838. Which best practice is being violated?

A.Using parentheses unnecessarily.
B.Not using an f-string to format the output.
C.Not rounding the result to two decimal places for currency.
D.Using multiplication instead of addition for tax.
AnswerC

Currency should be rounded to avoid floating-point imprecision.

Why this answer

Option C is correct because when dealing with currency values, best practice dictates rounding to two decimal places to represent cents. The raw result 161.838 is not a valid monetary amount; it should be rounded to 161.84 using `round(total, 2)` or formatted with `:.2f`. This ensures accuracy and avoids confusion in financial calculations.

Exam trap

Python Institute often tests the misconception that any arithmetic result is acceptable as long as the formula is correct, but the trap is that currency values require explicit rounding to two decimal places to follow financial best practices.

How to eliminate wrong answers

Option A is wrong because the parentheses are necessary to ensure the tax multiplier (1 + tax_rate) is computed before multiplication; without them, the expression would be evaluated incorrectly due to operator precedence. Option B is wrong because using an f-string is a formatting preference, not a best practice violation; the core issue is the lack of rounding, not the output method. Option D is wrong because the tax calculation correctly uses multiplication to apply the tax rate as a percentage; addition would incorrectly add a flat value instead of a proportional tax.

121
MCQmedium

A developer needs to read an integer from user input and store it. Which code snippet accomplishes this?

A.x = int(input())
B.x = read_int()
C.x = input(int())
D.x = int(input)
AnswerA

Correct; input() returns string, int() converts.

Why this answer

Option A is correct because `int(input())` first calls `input()` to read a string from the user, then passes that string to `int()` to convert it to an integer. This is the standard Python pattern for reading an integer from standard input.

Exam trap

Python Institute often tests the distinction between calling a function (with parentheses) and referencing it (without parentheses), so candidates mistakenly write `int(input)` instead of `int(input())`.

How to eliminate wrong answers

Option B is wrong because `read_int()` is not a built-in Python function; it would raise a NameError unless explicitly defined. Option C is wrong because `input(int())` attempts to call `int()` with no argument (which returns 0) and then passes that integer to `input()`, which expects a string prompt, causing a TypeError. Option D is wrong because `int(input)` passes the function object `input` (not its result) to `int()`, which raises a TypeError since `int()` expects a string or number, not a function.

122
Multi-Selecthard

Which THREE of the following expressions evaluate to True?

Select 3 answers
A.10 / 2 == 5.0
B.10 // 2 == 5
C.10 % 2 == 0
D.10 // 2 == 5.1
E.10 % 2 == 1
AnswersA, B, C

True. Division yields 5.0.

Why this answer

Option A is correct because the division operator `/` in Python always returns a float. Since 10 divided by 2 equals 5.0, and the comparison `==` checks value equality (not type), `5.0 == 5.0` evaluates to True.

Exam trap

Python Institute often tests the distinction between `/` (true division returning float) and `//` (floor division returning int), and the fact that modulo with even numbers always yields 0, tricking candidates who confuse remainder with quotient.

123
MCQhard

A developer is building a simple calculator that accepts two numbers and an operator string. The code: x = float(input("First: ")) y = float(input("Second: ")) op = input("Operator (+, -, *, /): ") if op == "+": result = x + y elif op == "-": result = x - y elif op == "*": result = x * y elif op == "/": result = x / y print("Result:", result) When the user enters 10, 3, and "/", the output is "Result: 3.3333333333333335". The developer wants to display only two decimal places. Which code change will achieve this without introducing errors?

A.Change print to: print("Result:", format(result, ".2f"))
B.Change print to: print("Result: " + str(result)[:4])
C.Change print to: print("Result:", result.toFixed(2))
D.Change print to: print("Result:", round(result, 2))
AnswerA

format with '.2f' always shows exactly two decimal places.

Why this answer

Option A is correct because the `format()` function with the format specifier `.2f` converts the floating-point result to a string rounded to two decimal places, which is exactly what the developer needs. This approach does not alter the original variable and works reliably for display purposes.

Exam trap

Python Institute often tests the distinction between rounding a number (which returns a float) and formatting a number for display (which returns a string), and the trap here is that candidates may think `round()` solves the display problem, but it does not guarantee a fixed number of decimal places in the output.

How to eliminate wrong answers

Option B is wrong because slicing the string representation of the result to the first four characters (e.g., '3.33') will fail for numbers with fewer digits before the decimal (e.g., 0.1234 becomes '0.12') or for negative numbers, and it does not perform proper rounding. Option C is wrong because Python does not have a `toFixed()` method; that is a JavaScript method, and using it will raise an AttributeError. Option D is wrong because `round(result, 2)` returns a float, and due to floating-point representation, the printed value may still show many decimal places (e.g., `round(3.3333333333333335, 2)` gives `3.33` but printing it directly may display `3.33` in some environments, but it is not guaranteed to always show exactly two decimal places—for example, `round(2.5, 2)` prints as `2.5`, not `2.50`—so it does not reliably force two decimal places in the output.

124
MCQmedium

A program contains this code: print(1 and 2 or 3). What is the output?

A.3
B.1
C.True
D.2
AnswerD

Evaluation: 1 and 2 -> 2; 2 or 3 -> 2.

Why this answer

In Python, the `and` and `or` operators short-circuit and return the last evaluated operand, not a boolean. `1 and 2` evaluates to `2` because both are truthy and `and` returns the last truthy value. Then `2 or 3` short-circuits because `2` is truthy, so `or` returns `2` without evaluating `3`. Thus, the output is `2`.

Exam trap

Python Institute often tests the misconception that `and`/`or` always return `True` or `False`, leading candidates to pick `True` (option C) instead of the actual operand value `2`.

How to eliminate wrong answers

Option A is wrong because `3` would only be returned if both `1` and `2` were falsy in an `or` chain, but here `2` is truthy and short-circuits the `or`. Option B is wrong because `1` is not the final result; `and` returns the last truthy operand (`2`), not the first. Option C is wrong because the expression does not return a boolean `True`; it returns the actual operand value `2`, which is truthy but not the boolean `True`.

125
MCQeasy

Refer to the exhibit. What is the output of the Python code?

A.['abc', 'abc', 'abc']
B.abcabc abc
C.abc abc abc
D.abcabcabc
AnswerD

Correct: repeats string 3 times.

Why this answer

The code uses the multiplication operator on a list containing the string 'abc'. In Python, multiplying a list by an integer repeats the list's elements that many times. The result is a new list with three copies of 'abc', which when printed directly shows ['abc', 'abc', 'abc'].

However, the question asks for the output of the code, and the correct output is the string representation of the list, which is 'abcabcabc' only if the list is joined without spaces. But the code does not join the list; it prints the list object, so the output is actually ['abc', 'abc', 'abc']. Wait, the correct answer according to the options is D, which suggests the code prints the concatenated string 'abcabcabc'.

This implies the code might be using the multiplication operator on a string, not a list. The exhibit likely shows `print('abc' * 3)`, which outputs 'abcabcabc'.

Exam trap

The trap here is that candidates often confuse string multiplication with list multiplication or expect spaces between repetitions, but Python's string multiplication concatenates the string directly without any separator.

How to eliminate wrong answers

Option A is wrong because it shows a list with three 'abc' strings, which would be the output if the code used `['abc'] * 3` and printed the list, but the correct code uses string multiplication, not list multiplication. Option B is wrong because it shows 'abcabc abc' with a space, which would result from printing a list or using incorrect concatenation, but string multiplication does not insert spaces. Option C is wrong because it shows 'abc abc abc' with spaces, which would be the output of `print('abc', 'abc', 'abc')` or using `join` with spaces, not string multiplication.

126
MCQhard

Refer to the exhibit. A beginner Python programmer executes the code and gets an error. What is the most likely cause?

A.The variables x and y are of incompatible types for the + operator
B.The + operator cannot be used with print()
C.The variable y should be converted to an integer using int()
D.The print function is misspelled
AnswerA

Correct: int and str cannot be added with +

Why this answer

Option A is correct because the error occurs when the + operator is used between incompatible types, such as a string (x) and an integer (y). In Python, the + operator performs concatenation for strings and addition for numbers, but mixing types without explicit conversion raises a TypeError. The code likely defines x as a string (e.g., '10') and y as an integer (e.g., 5), causing the error.

Exam trap

Python Institute often tests the misconception that the + operator can automatically convert types, leading candidates to overlook the need for explicit type conversion or to incorrectly blame the print function.

How to eliminate wrong answers

Option B is wrong because the + operator can be used inside print() to concatenate strings or add numbers, and it is a common and valid usage. Option C is wrong because converting y to an integer using int() would not fix the error if y is already an integer; the issue is that x is a string, not that y needs conversion. Option D is wrong because the print function is correctly spelled in the code (assuming the exhibit shows 'print'), and a misspelling would cause a NameError, not a TypeError from the + operator.

127
MCQhard

A function is designed to return False if a number is not divisible by 2. Which of the following return statements correctly implements this logic?

A.return n % 2 != 0
B.return n % 2 == 1
C.return not n % 2 == 0
D.return n % 2 == 0
AnswerD

Correct. Returns True if divisible, False otherwise, matching the requirement.

Why this answer

Option D is correct because the function must return False when the number is not divisible by 2. The expression `n % 2 == 0` evaluates to True when n is even (divisible by 2) and False when n is odd (not divisible by 2), directly matching the required logic.

Exam trap

The trap here is that candidates often confuse the condition for divisibility (n % 2 == 0) with the condition for non-divisibility (n % 2 != 0), leading them to select an option that returns the opposite boolean value.

How to eliminate wrong answers

Option A is wrong because `return n % 2 != 0` returns True when n is not divisible by 2 (odd) and False when divisible by 2 (even), which is the inverse of the required logic. Option B is wrong because `return n % 2 == 1` works only for positive odd numbers; in Python, the modulo operation with negative numbers can yield -1 instead of 1, making this unreliable for all integers. Option C is wrong because `return not n % 2 == 0` is logically equivalent to `return n % 2 != 0`, thus also returning the inverse of the required result.

128
MCQhard

A developer writes: a = 3; b = 4; c = a + b / 2. What is the value of c?

A.3
B.3.5
C.5
D.5.0
AnswerD

3 + 4/2 = 3 + 2.0 = 5.0.

Why this answer

In Python, the division operator `/` always returns a float, and operator precedence dictates that division is performed before addition. Thus, `b / 2` evaluates to `4 / 2 = 2.0`, then `a + 2.0` yields `3 + 2.0 = 5.0`. Option D is correct because the result is a float value of 5.0.

Exam trap

Python Institute often tests the combination of operator precedence and the fact that `/` always returns a float in Python 3, trapping candidates who expect integer division or who incorrectly group the expression as `(a + b) / 2`.

How to eliminate wrong answers

Option A is wrong because it incorrectly assumes integer division or that the expression evaluates to 3, ignoring the division and addition. Option B is wrong because it suggests the result is 3.5, which would occur if the expression were `(a + b) / 2` due to incorrect grouping. Option C is wrong because it gives the integer 5, but Python's `/` operator always returns a float, so the result is 5.0, not the int 5.

129
MCQhard

A developer needs to convert a string '25' to an integer and then add 10. Which code correctly performs this?

A.print(int('25') + 10)
B.print('25' + 10)
C.print(int('25') + '10')
D.print('25' + str(10))
AnswerA

Correct conversion and addition.

Why this answer

Option A is correct because `int('25')` converts the string '25' to the integer 25, and then `+ 10` performs integer addition, resulting in 35. The `print()` function outputs the result. This follows Python's type conversion rules where explicit conversion is required to combine a string and an integer in arithmetic.

Exam trap

Python Institute often tests the misconception that Python will automatically convert types in arithmetic expressions, leading candidates to choose options that mix strings and integers without explicit conversion.

How to eliminate wrong answers

Option B is wrong because it attempts to add a string ('25') and an integer (10) directly, which raises a TypeError in Python as the `+` operator is not defined for mixed string-integer operands. Option C is wrong because it adds an integer (from `int('25')`) to a string ('10'), which also raises a TypeError for the same reason. Option D is wrong because it concatenates the string '25' with the string '10' (from `str(10)`), producing '2510' rather than performing arithmetic addition.

130
MCQeasy

A student tries to write a program that prints the square of a number. The code: num = 5 print("The square is " + num ** 2) When run, a TypeError occurs. Which of the following fixes the error and produces exactly the output 'The square is 25'?

A.Change to: print("The square is " + str(num ** 2))
B.Change to: print("The square is " + num ** 2)
C.Change to: print("The square is", num ** 2)
D.Change to: print("The square is " + (num ** 2))
AnswerA

str() converts the integer to string for concatenation.

Why this answer

Option A is correct because it converts the integer result of `num ** 2` (which is 25) to a string using `str()`, allowing concatenation with the string literal `"The square is "`. Without this conversion, Python raises a `TypeError` because the `+` operator cannot concatenate a string and an integer directly.

Exam trap

Python Institute often tests the distinction between concatenation with `+` (which requires matching types) and the `print()` function's multiple arguments with commas (which automatically adds a space separator but does not require type conversion), leading candidates to mistakenly choose Option C when the exact output string must match.

How to eliminate wrong answers

Option B is wrong because it is identical to the original erroneous code — it still tries to concatenate a string with an integer, causing a `TypeError`. Option C is wrong because although it runs without error and prints `The square is 25`, it uses a comma separator which inserts a space automatically, producing `The square is 25` (with a space before the number) — but the question requires exactly the output `'The square is 25'` (no extra space before 25), so it does not match. Option D is wrong because wrapping `num ** 2` in parentheses does not change its type; it remains an integer, so the `TypeError` persists.

131
Multi-Selecthard

Given the following code, which of the following statements are true after execution? (Choose three.) x = 10 y = 3.0 z = x / y w = x // y

Select 3 answers
A.The expression x % y is valid.
B.The value of z is approximately 3.33 (type float).
C.The type of w is int.
D.The expression x / y returns an integer.
E.The value of w is 3.0.
AnswersA, B, E

Modulo works with floats.

Why this answer

Option A is correct because the modulo operator % works with both integers and floats in Python. Here, x is an int and y is a float, so x % y is valid and returns a float result (the remainder of the division).

Exam trap

Cisco often tests the misconception that floor division (//) returns an int when one operand is a float, or that true division (/) can return an integer, leading candidates to incorrectly select options C or D.

132
MCQmedium

A program needs to read a user's age and print a message if they are 18 or older. Which code snippet correctly accomplishes this?

A.age = int(input('Age: ')) if age >= '18': print('Adult')
B.age = int(input('Age: ')) if age >= 18: print('Adult')
C.age = input('Age: ') if age >= 18: print('Adult')
D.age = input('Age: ') if age == 18: print('Adult')
AnswerB

Correct conversion and comparison.

Why this answer

Option B is correct because it uses `int()` to convert the user input to an integer, then compares it with the integer `18` using the `>=` operator. This ensures a proper numeric comparison, and if the condition is true, it prints 'Adult'.

Exam trap

Python Institute often tests the distinction between string and integer types, and the trap here is that candidates forget to convert the input to an integer, leading to a type mismatch error when using comparison operators like `>=`.

How to eliminate wrong answers

Option A is wrong because it compares an integer (`age`) with a string `'18'`, which in Python 3 raises a `TypeError` (or in some contexts may produce unexpected results). Option C is wrong because `input()` returns a string, and comparing a string to the integer `18` with `>=` raises a `TypeError` (strings and integers cannot be compared with relational operators). Option D is wrong because it uses `==` instead of `>=`, so it only prints 'Adult' when the age is exactly 18, not for ages greater than 18, and also compares a string (from `input()`) to an integer, which would raise a `TypeError`.

133
MCQmedium

A junior developer writes: x = 10; y = 3; print(x % y). What will be printed?

A.3.33
B.1
C.0
D.3
AnswerB

Remainder when 10 is divided by 3.

Why this answer

The modulo operator (%) returns the remainder of the division of the left operand by the right operand. Here, 10 divided by 3 equals 3 with a remainder of 1, so print(x % y) outputs 1.

Exam trap

Python Institute often tests the distinction between the modulo operator (%) and integer division (//) or floating-point division (/), trapping candidates who confuse remainder with quotient or decimal result.

How to eliminate wrong answers

Option A is wrong because 3.33 would be the result of floating-point division (10 / 3), not the modulo operation. Option C is wrong because 0 would only occur if the division had no remainder (e.g., 9 % 3). Option D is wrong because 3 is the quotient of integer division (10 // 3), not the remainder from modulo.

134
MCQhard

Given 's = "Hello"; t = s[0:3]; print(t)', what is the output?

A.ello
B.H
C.Hell
D.Hel
AnswerD

s[0:3] gives first three characters.

Why this answer

Option D is correct because string slicing in Python uses the syntax `s[start:stop]`, where the stop index is exclusive. For `s = "Hello"`, `s[0:3]` extracts characters from index 0 up to but not including index 3, resulting in indices 0 ('H'), 1 ('e'), and 2 ('l'), giving the substring "Hel".

Exam trap

The trap here is that candidates often confuse the exclusive stop index with an inclusive one, leading them to select "Hell" (option C) because they mistakenly include index 3, or they misremember the starting index and pick "ello" (option A).

How to eliminate wrong answers

Option A is wrong because it represents `s[1:5]` (or `s[1:]`), which would skip the first character, not the slice `s[0:3]`. Option B is wrong because it represents `s[0:1]`, which extracts only the first character, not the first three. Option C is wrong because it represents `s[0:4]`, which includes index 3 ('l') and would output "Hell", but the correct slice stops at index 3 (exclusive), so only "Hel" is produced.

135
MCQeasy

A developer writes a script to read user input using input() and then prints it. However, the program crashes when the user enters a number. What is the most likely cause?

A.The input is read as a string, but the code treats it as a number without conversion.
B.The script uses Python 2, where input() evaluates input as code.
C.The print() function expects a string, but the input is a number.
D.The input() function cannot handle numeric input.
AnswerA

Correct: input() returns a string, so numeric operations fail.

Why this answer

The `input()` function in Python 3 always returns a string, regardless of what the user types. If the user enters a number, the program may crash if the code later performs an operation (like arithmetic or comparison) on that string without first converting it to an integer or float using `int()` or `float()`. This mismatch between the string type and the expected numeric type causes a `TypeError`.

Exam trap

Python Institute often tests the misconception that `input()` can return different types based on the input, when in Python 3 it always returns a string, leading candidates to overlook the need for explicit conversion.

How to eliminate wrong answers

Option B is wrong because in Python 2, `input()` evaluates the input as Python code, which could cause crashes with numeric input, but the question context (PCEP exam) assumes Python 3, where `input()` returns a string. Option C is wrong because `print()` can handle any data type, including numbers, by converting them to strings automatically. Option D is wrong because `input()` can handle numeric input perfectly fine; it just stores it as a string, which is not a crash in itself.

136
Multi-Selecteasy

Which THREE of the following are Python data types?

Select 3 answers
A.str
B.math
C.bool
D.float
E.None
AnswersA, C, D

String is a data type.

Why this answer

Option A is correct because `str` is a built-in Python data type used to represent sequences of characters, i.e., strings. In Python, strings are immutable and are defined by enclosing text in single, double, or triple quotes.

Exam trap

Cisco often tests the distinction between a data type and a module or a value, so candidates may mistakenly select `math` (a module) or `None` (a value) as data types because they appear frequently in Python code.

137
MCQmedium

Which data type is most appropriate to store a user's age in a Python program?

A.int
B.float
C.bool
D.str
AnswerA

Correct. Age is a whole number.

Why this answer

A user's age is a whole number without a fractional component, so the integer type (int) is the most appropriate choice. Python's int can represent any integer value, including ages like 25 or 0, without the overhead or precision issues of floating-point numbers.

Exam trap

Python Institute often tests the distinction between numeric types by presenting a scenario where a float seems plausible (e.g., 'age could be 25.5 years'), but the PCEP expects you to recognize that age is conventionally an integer and that Python's int is the correct choice for whole-number data.

How to eliminate wrong answers

Option B (float) is wrong because age is always a whole number; using float would introduce unnecessary decimal precision and potential rounding errors, such as representing 25 as 25.0. Option C (bool) is wrong because a boolean can only store True or False (1 or 0), which cannot represent the full range of possible ages. Option D (str) is wrong because while a string could store an age like '25', it would prevent arithmetic operations (e.g., age + 1) and is semantically incorrect for a numeric value.

138
MCQhard

Which of the following expressions will evaluate to True?

A.3 == 3.0
B.2 + 2 * 2 == 8
C.10 / 3 == 3
D.'a' > 'b'
AnswerA

True, numeric comparison converts 3.0 to 3.

Why this answer

Option A is correct because Python's `==` operator performs value equality comparison, and the integer `3` and the float `3.0` represent the same numeric value. Python automatically converts the integer to a float for comparison, so `3 == 3.0` evaluates to `True`.

Exam trap

Python Institute often tests the misconception that `==` requires identical data types, leading candidates to think `3 == 3.0` is `False`, or that operator precedence is left-to-right without considering multiplication before addition.

How to eliminate wrong answers

Option B is wrong because operator precedence in Python dictates that multiplication (`*`) is evaluated before addition (`+`), so `2 + 2 * 2` equals `2 + 4 = 6`, not `8`, making `6 == 8` evaluate to `False`. Option C is wrong because the division operator `/` in Python 3 always returns a float, and `10 / 3` yields `3.3333333333333335`, which is not equal to the integer `3`, so `10 / 3 == 3` is `False`. Option D is wrong because string comparison in Python uses lexicographic order based on ASCII/Unicode code points; the character `'a'` has a Unicode code point of 97, while `'b'` has 98, so `'a' > 'b'` evaluates to `False`.

139
MCQmedium

A program calculates the total price including tax: total = price * 1.08. The variable price is assigned as price = 100.0. After execution, total is 108.0. The developer then changes price to 100. What will total be?

A.The program will raise a TypeError
B.It depends on the Python version
C.108.0
D.108
AnswerC

Correct: float * int yields float.

Why this answer

Option C is correct because in Python, multiplying an integer (100) by a float (1.08) results in a float (108.0). The expression `price * 1.08` performs implicit type coercion to float, so even when `price` is changed from 100.0 to 100, the result remains 108.0, not 108.

Exam trap

Python Institute often tests the misconception that changing an integer literal to a float literal changes the result type, when in fact the result type is determined by the wider operand (the float 1.08) regardless of whether price is 100 or 100.0.

How to eliminate wrong answers

Option A is wrong because Python does not raise a TypeError when multiplying an int by a float; it performs implicit type conversion and returns a float. Option B is wrong because the behavior of mixed-type arithmetic is consistent across all Python 3 versions—int * float always yields a float. Option D is wrong because the result is 108.0 (a float), not 108 (an int), due to the presence of the float literal 1.08 in the multiplication.

140
MCQeasy

A junior developer writes: result = input("Enter first: ") + input("Enter second: ") and then prints result. When entering 5 and 3, the output is '53'. Which explanation is correct?

A.The code uses the wrong operator; it should use the & operator for addition.
B.The input() function automatically selects the correct type, but the + operator is overloaded to concatenate.
C.Python automatically converts strings to numbers when using +, but only for integers.
D.The input() function returns a string, so + performs string concatenation.
AnswerD

input() always returns a string, so + concatenates.

Why this answer

Option D is correct because the `input()` function in Python always returns a string, regardless of what the user types. When the `+` operator is used with two strings, it performs concatenation, not arithmetic addition. Thus, entering 5 and 3 results in the strings '5' and '3' being joined to produce '53'.

Exam trap

The trap here is that candidates may assume `input()` returns a numeric type when numbers are entered, or that Python's dynamic typing will automatically convert strings to numbers for addition, leading them to choose option B or C instead of recognizing the default string behavior.

How to eliminate wrong answers

Option A is wrong because the `&` operator is a bitwise AND operator in Python, not an arithmetic addition operator; using it would produce a different, incorrect result. Option B is wrong because `input()` does not automatically select the correct type; it always returns a string, and the `+` operator is overloaded to concatenate strings, but that is not an automatic type selection. Option C is wrong because Python does not automatically convert strings to numbers when using `+`; attempting to add a string and a number with `+` raises a TypeError, and the statement about 'only for integers' is false.

141
MCQmedium

Refer to the exhibit. If the user enters 5 and 3, what is the output?

A.8
B.5 3
C.TypeError
D.53
AnswerD

String concatenation of '5' and '3'.

Why this answer

In Python, the `input()` function always returns a string. When the user enters 5 and 3, the `+` operator concatenates the two strings '5' and '3', producing the string '53'. Option D is correct because no numeric conversion is performed.

Exam trap

Python Institute often tests the misconception that `input()` returns a numeric type when digits are entered, leading candidates to expect arithmetic addition instead of string concatenation.

How to eliminate wrong answers

Option A is wrong because it assumes the inputs are automatically converted to integers and added, but `input()` returns strings and no `int()` conversion is applied. Option B is wrong because it suggests the output is the two numbers separated by a space, but the `+` operator concatenates them without a space. Option C is wrong because there is no TypeError; string concatenation with `+` is valid and produces a string result.

142
MCQmedium

What is the output of print(10 // 3, 10 % 3)?

A.1 3
B.3.33 1
C.3 3
D.3 1
AnswerD

Correct: 10//3=3, 10%3=1.

Why this answer

Option D is correct because the // operator performs floor division, which divides 10 by 3 and discards the fractional part, yielding 3. The % operator returns the remainder of that division, which is 1. The print function outputs both values separated by a space, resulting in '3 1'.

Exam trap

Python Institute often tests the distinction between floor division (//) and true division (/), and the trap here is that candidates mistakenly think // performs regular division or confuse the order of quotient and remainder in the output.

How to eliminate wrong answers

Option A is wrong because it reverses the results, showing the remainder first (1) and the quotient second (3), which misinterprets the order of operations in the print statement. Option B is wrong because it uses true division (/) instead of floor division (//), giving 3.33, and incorrectly pairs it with remainder 1. Option C is wrong because it shows the quotient as 3 but incorrectly gives the remainder as 3, likely confusing the remainder with the divisor or the quotient itself.

143
MCQeasy

Which of the following variable names is valid in Python?

A.1st_value
B._count
C.my-var
D.class
AnswerB

Valid: underscores are allowed at the start.

Why this answer

Option B (_count) is valid because Python allows identifiers to start with an underscore, and it contains only letters and underscores. Python variable names must start with a letter or underscore, followed by letters, digits, or underscores, and cannot be a reserved keyword.

Exam trap

Python Institute often tests the misconception that underscores are not allowed or that hyphens are acceptable in variable names, leading candidates to reject _count or accept my-var.

How to eliminate wrong answers

Option A is wrong because variable names cannot start with a digit; '1st_value' begins with '1', which violates Python's identifier rules. Option C is wrong because hyphens are not allowed in Python identifiers; 'my-var' uses a hyphen, which Python interprets as a subtraction operator. Option D is wrong because 'class' is a reserved keyword in Python used to define classes, so it cannot be used as a variable name.

144
MCQeasy

A developer writes: x = 5; y = 2.0; z = x / y; print(type(z)). What is the output?

A.<class 'str'>
B.<class 'int'>
C.TypeError
D.<class 'float'>
AnswerD

x / y returns a float because y is float.

Why this answer

In Python, the division operator (/) always returns a float, even when dividing two integers. Here, x is an integer (5) and y is a float (2.0), so the result is a float (2.5). The type() function returns <class 'float'>, making D correct.

Exam trap

Python Institute often tests the distinction between / (true division, always returns float) and // (floor division, returns int for int operands) to catch candidates who assume integer division returns an integer.

How to eliminate wrong answers

Option A is wrong because the result of division is a number, not a string; type() would never return <class 'str'> for a numeric operation. Option B is wrong because Python 3's / operator always produces a float, even if the division is exact (e.g., 5/5 returns 1.0, not 1). Option C is wrong because there is no TypeError; Python allows division between int and float without issue, implicitly converting the int to a float for the operation.

145
MCQmedium

An accountant uses a Python script to calculate tax: tax = price * 0.08. For price=19.99, tax results in 1.5992. However, the output should be rounded to two decimal places. Which expression should replace the current one?

A.tax = round(price * 0.08)
B.tax = round(price * 0.08, 2)
C.tax = price * 0.08
D.tax = int(price * 0.08 * 100) / 100
AnswerB

Correctly rounds to two decimal places.

Why this answer

Option B is correct because the built-in `round()` function with a second argument of 2 rounds the floating-point result of `price * 0.08` to exactly two decimal places, which matches the requirement for currency formatting. The other options either omit rounding, round to an integer, or use integer truncation that can produce incorrect results for negative numbers or edge cases.

Exam trap

Python Institute often tests the distinction between `round(x)` (rounds to integer) and `round(x, n)` (rounds to n decimal places), and the trap here is that candidates may choose Option A thinking it rounds to two decimals, or Option D thinking integer truncation is equivalent to rounding.

How to eliminate wrong answers

Option A is wrong because `round(price * 0.08)` with no second argument rounds to the nearest integer (0 decimal places), producing 2 instead of 1.60. Option C is wrong because it simply computes the raw floating-point value 1.5992 without any rounding, leaving extra decimal places. Option D is wrong because `int(price * 0.08 * 100) / 100` truncates toward zero, which for positive values works here but fails for negative numbers (e.g., -19.99 would give -1.59 instead of -1.60) and does not perform proper rounding.

146
MCQmedium

Refer to the exhibit. Which of the following shows the correct output?

A.3.3333333333333335 4 1
B.3.3333333333333335 3 1
C.3.0 3.0 1.0
D.3 3 0
AnswerB

Correct outputs.

Why this answer

Option B is correct because the code `print(10/3)` performs floating-point division in Python 3, yielding `3.3333333333333335`; `print(10//3)` performs floor division, which truncates to the nearest integer less than or equal to the result, giving `3`; and `print(10%3)` computes the remainder of the division, which is `1`.

Exam trap

The trap here is that candidates often confuse the behavior of the `/` operator (which always returns a float in Python 3) with integer division from Python 2, or they misapply floor division and remainder operations, especially when dealing with positive integers.

How to eliminate wrong answers

Option A is wrong because it shows `4` for the floor division `10//3`, but floor division of 10 by 3 correctly yields `3`, not `4`. Option C is wrong because it shows `3.0` for both `10/3` and `10//3`, but `10/3` is a float with a fractional part, not exactly `3.0`, and `10//3` returns an integer `3`, not a float `3.0`. Option D is wrong because it shows `3` for `10/3`, but `10/3` returns a float `3.3333333333333335`, not an integer `3`, and it shows `0` for `10%3`, but the remainder of 10 divided by 3 is `1`, not `0`.

147
Multi-Selectmedium

Which TWO of the following are valid ways to create a variable with the integer value 100?

Select 2 answers
A.x = 0100
B.x = 100.0
C.x = int('100')
D.x = 100
E.x = '100'
AnswersC, D

Converts string to integer.

Why this answer

Option C is correct because the `int()` function converts a string containing a valid integer literal, such as '100', into an integer value of 100. This is a standard type-casting operation in Python that explicitly creates an integer from a string representation.

Exam trap

Python Institute often tests the distinction between numeric literals (like `100`), string literals (like `'100'`), and type conversion functions (like `int()`), and the trap here is that candidates may mistakenly think a string with digits is automatically an integer or that a float literal like `100.0` is equivalent to an integer.

148
MCQeasy

What is the output from the interactive Python session?

A.3.333 1
B.3 1
C.1 3
D.3 0
AnswerB

10 // 3 = 3, 10 % 3 = 1.

Why this answer

The expression `10 // 3` performs integer (floor) division, which discards the fractional part and returns the integer quotient 3. The expression `10 % 3` returns the remainder of the division, which is 1. Therefore, the output is `3 1`, making option B correct.

Exam trap

Python Institute often tests the distinction between true division (`/`) and floor division (`//`), knowing that candidates may confuse the two or forget that integer division in Python 3 returns an integer, not a float.

How to eliminate wrong answers

Option A is wrong because it suggests `10 // 3` yields 3.333, which would be the result of true division (`10 / 3`) in Python 3, not floor division. Option C is wrong because it reverses the order of the results, outputting `1 3` instead of `3 1`. Option D is wrong because it claims the remainder is 0, but `10 % 3` correctly yields 1, not 0.

149
Drag & Dropmedium

Order the steps to debug a Python script using print statements.

Drag steps to the numbered slots on the right, or tap a step then tap a slot.

Steps
Order

Why this order

Debugging with print involves inserting prints, running, analyzing, and cleaning up.

← PreviousPage 2 of 3 · 196 questions totalNext →

Ready to test yourself?

Try a timed practice session using only Data Types, Variables, Basic I/O and Operators questions.