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

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

1
MCQhard

What is the output of the following code? print(type(3.0) == float)

A.<class 'bool'>
B.False
C.Error
D.True
AnswerD

Correct; type returns <class 'float'>, which equals float.

Why this answer

The expression `type(3.0) == float` compares the result of `type(3.0)` (which is `<class 'float'>`) directly to the `float` class. In Python, `type()` returns the class object, and comparing it with `==` to the built-in class `float` yields `True` because they are the same object. Therefore, `print(True)` outputs `True`.

Exam trap

Python Institute often tests the distinction between `type()` returning a class object versus a string representation, and candidates mistakenly think `type(3.0)` returns the string `'float'`, leading them to choose `False` or `Error`.

How to eliminate wrong answers

Option A is wrong because `print()` outputs the value of the expression, not its type; the expression evaluates to `True`, which is a boolean, but the output is the string representation `True`, not `<class 'bool'>`. Option B is wrong because the comparison `type(3.0) == float` is `True`, not `False`; a common mistake is thinking `type()` returns a string like `'float'`, but it returns the actual class object. Option C is wrong because the code is syntactically valid and runs without any error; `type(3.0)` is a valid call, and comparing it with `==` to `float` is allowed.

2
Multi-Selecthard

Which two of the following expressions return the value 5? (Choose two.)

Select 2 answers
A.10 % 5
B.10 // 2
C.10 ** 0
D.10 / 2
E.5 * 1
AnswersB, E

Floor division yields 5

Why this answer

Option B (10 // 2) uses floor division, which divides 10 by 2 and returns the integer quotient 5. This is correct because floor division in Python discards any fractional remainder, yielding an exact integer result.

Exam trap

Python Institute often tests the difference between / (float division) and // (integer floor division), trapping candidates who assume / returns an integer when the division is exact.

3
MCQhard

A function sometimes returns None. Which expression correctly checks if the return value is not None?

A.if not val is None:
B.if val != None:
C.if val is not None:
D.if val:
AnswerC

Correct and idiomatic.

Why this answer

Option C is correct because the `is not` operator is the proper way to check identity inequality in Python. Since `None` is a singleton, comparing with `is not` ensures you are checking whether the value is literally the `None` object, which is the recommended and most readable approach for `None` checks.

Exam trap

Python Institute often tests the distinction between identity (`is`) and equality (`==`) operators, and the trap here is that candidates mistakenly use `!= None` (value comparison) instead of `is not None` (identity comparison), or confuse truthiness checks with `None` checks.

How to eliminate wrong answers

Option A is wrong because `if not val is None:` is syntactically valid but confusing and non-idiomatic; it actually means `if not (val is None):` due to operator precedence, which is equivalent to `if val is not None:` but is discouraged for readability. Option B is wrong because `if val != None:` uses value equality (`!=`) instead of identity (`is not`); while it often works due to Python's implementation, it can fail if the object's `__eq__` method is overridden to return `True` when compared to `None`. Option D is wrong because `if val:` checks truthiness, not whether the value is `None`; many falsy values (e.g., `0`, `False`, empty list) would cause the condition to be `False` even though they are not `None`.

4
MCQeasy

A developer writes the following code: result = (5 + 3) * 2 ** 3 // 4. What is the value of result?

A.8
B.16
C.13
D.64
AnswerB

Correct: follows precedence and left-associativity.

Why this answer

Option B is correct because Python follows the operator precedence rules: exponentiation (**) is evaluated before multiplication and division, and multiplication/division are evaluated before addition/subtraction. The expression evaluates as: 2 ** 3 = 8, then (5 + 3) = 8, then 8 * 8 = 64, then 64 // 4 = 16. The integer division (//) yields an integer result of 16.

Exam trap

Python Institute often tests the combination of exponentiation and floor division with parentheses, where candidates forget that ** binds tighter than * and //, leading them to compute (5+3)*2 = 16, then 16**3 = 4096, then 4096//4 = 1024, or they ignore the // and just compute 8*8=64.

How to eliminate wrong answers

Option A is wrong because it assumes the expression is evaluated left-to-right without precedence, e.g., (5+3)=8, then 8*2=16, then 16**3=4096, then 4096//4=1024, which is not 8; or it might incorrectly compute 2**3=8, then 8//4=2, then 8*2=16, but then subtract something incorrectly. Option C is wrong because it likely results from misapplying precedence, e.g., computing (5+3)=8, then 2**3=8, then 8*8=64, then 64/4=16.0 (float) but then rounding or truncating incorrectly to 13, or mixing // with / in a wrong order. Option D is wrong because it ignores the floor division (//) entirely, computing 8 * 8 = 64 and stopping, or it incorrectly treats // as exponentiation again.

5
MCQeasy

Which of the following is a valid Python variable name?

A.2var
B.var name
C.var-name
D._var
AnswerD

Underscore is allowed as first character.

Why this answer

Option D (_var) is correct because in Python, variable names must start with a letter or an underscore, and can contain letters, digits, and underscores. The underscore is explicitly allowed as the first character, making _var a valid identifier.

Exam trap

Python Institute often tests the misconception that hyphens or spaces are acceptable in variable names because they appear in other programming languages or file naming conventions, but Python strictly prohibits them.

How to eliminate wrong answers

Option A is wrong because variable names cannot start with a digit; '2var' begins with '2', which violates Python's identifier rules. Option B is wrong because variable names cannot contain spaces; 'var name' includes a space, which is not a valid character in identifiers. Option C is wrong because variable names cannot contain hyphens; 'var-name' uses a hyphen, which Python interprets as the subtraction operator, not part of a name.

6
MCQmedium

A developer needs to store the result of dividing two numbers, a/b, but only if b is not zero. They write: result = a / b if b != 0 else 'undefined'. What is the data type of result when b is zero?

A.float
B.NoneType
C.bool
D.str
AnswerD

The else clause returns a string literal, so result is a string.

Why this answer

When `b` is zero, the expression `a / b if b != 0 else 'undefined'` evaluates to the string literal `'undefined'`. Therefore, the variable `result` is assigned a value of type `str` (string). The conditional expression explicitly returns a string in the else branch, making option D correct.

Exam trap

Python Institute often tests the ternary conditional expression to see if candidates mistakenly think the else branch returns a special 'undefined' value (like in JavaScript) instead of recognizing it as a plain Python string literal.

How to eliminate wrong answers

Option A is wrong because a float is returned only when the division occurs (b != 0); when b is zero, no division happens, so no float is produced. Option B is wrong because NoneType would require the expression to evaluate to `None`, but the else clause explicitly returns the string `'undefined'`, not the Python `None` object. Option C is wrong because a bool would require the expression to evaluate to `True` or `False`, but the else clause returns a string, not a boolean.

7
Matchingmedium

Match each Python control flow statement to its purpose.

Drag a concept onto its matching description — or click a concept then click the description.

Concepts
Matches

Exits the current loop immediately

Skips the rest of the current iteration and goes to the next

Does nothing; used as a placeholder

Short for else-if; checks another condition

Executes a block when no previous condition is true

Why these pairings

These statements control the execution flow in Python loops and conditionals.

8
Multi-Selecthard

Which THREE of the following statements about Python operators are true?

Select 3 answers
A.The not operator is a logical operator that negates a condition.
B.The // operator performs floor division.
C.The ** operator is the bitwise XOR operator.
D.The / operator always returns an integer if both operands are integers.
E.The % operator returns the remainder of division.
AnswersA, B, E

Correct.

Why this answer

Option A is correct because the `not` operator is a logical operator in Python that returns the Boolean negation of its operand: if the operand is `True`, `not` returns `False`, and vice versa. This is fundamental to Boolean logic and conditional expressions in Python.

Exam trap

Python Institute often tests the Python 3-specific change that the `/` operator always returns a float, trapping candidates who remember the Python 2 behavior where `/` performed integer division on integers.

9
MCQeasy

A beginner writes: x = '10'; y = 20; print(x + y). What happens?

A.Raises TypeError
B.Prints 30
C.Prints 10 + 20
D.Prints 1020
AnswerA

Incompatible types for +.

Why this answer

Option A is correct because Python's type system does not allow implicit concatenation of a string and an integer. The variable `x` is a string (`'10'`), and `y` is an integer (`20`). The `+` operator with these types triggers a `TypeError: unsupported operand type(s) for +: 'int' and 'str'` (or vice versa), as Python refuses to guess the programmer's intent.

Exam trap

The trap here is that candidates often expect Python to behave like JavaScript or PHP, which implicitly coerce types, but Python strictly requires explicit type conversion for mixed-type operations.

How to eliminate wrong answers

Option B is wrong because it assumes Python will implicitly convert the string to an integer and perform numeric addition, which Python does not do for mixed types. Option C is wrong because it treats the `+` operator as a literal string concatenation in the output, but Python evaluates expressions, not printing the source code. Option D is wrong because it assumes Python will implicitly convert the integer to a string and concatenate them as `'10' + '20'` → `'1020'`, but Python raises a TypeError instead of performing implicit type coercion.

10
MCQmedium

A developer writes: num = input('Enter a number: '); result = num * 2; print(result). If the user enters 5, what is the output?

A.Error: cannot multiply string by int
B.10
C.'5' * 2
D.55
AnswerD

String '5' multiplied by 2 gives '55'.

Why this answer

Option D is correct because the `input()` function always returns a string. When the user enters '5', `num` is the string '5', not the integer 5. The `*` operator on a string performs repetition, so `'5' * 2` produces '55', which is printed as 55.

Exam trap

Python Institute often tests the misconception that `input()` returns a numeric type when the user types digits, leading candidates to expect arithmetic multiplication instead of string repetition.

How to eliminate wrong answers

Option A is wrong because Python does not raise an error when multiplying a string by an integer; it performs string repetition. Option B is wrong because it assumes `input()` returns an integer, but it returns a string, so numeric multiplication does not occur. Option C is wrong because it shows the raw expression `'5' * 2` as output, but `print()` outputs the resulting string '55', not the expression.

11
MCQeasy

Which data type is the result of: value = 10 // 3?

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

Correct: // with two ints returns int.

Why this answer

The // operator in Python performs floor division, which divides the left operand by the right operand and returns the largest integer less than or equal to the result. Since both 10 and 3 are integers, the result is an integer (3), not a float. Therefore, the data type of value is int.

Exam trap

Python Institute often tests the distinction between / (true division returning float) and // (floor division returning int), trapping candidates who assume all division in Python returns a float.

How to eliminate wrong answers

Option A is wrong because floor division (//) with integer operands always returns an int, not a float; a float result would require the / operator (true division). Option B is wrong because the result is a numeric value, not a string; str would only be produced by explicit conversion or string concatenation. Option D is wrong because the result is a numeric integer, not a Boolean; bool would only be returned by comparison operators (e.g., ==, >) or logical operations.

12
MCQhard

A script uses the input() function to get a user's age: age = input('Enter age: '). Later it computes age > 18. This raises a TypeError. What is the root cause?

A.The input() function cannot read numbers.
B.The variable age is automatically converted to int.
C.The variable age is a string, not an integer.
D.The comparison operator > is not valid for strings.
AnswerC

input() returns string; convert to int first.

Why this answer

Option C is correct because the `input()` function in Python always returns a string, regardless of what the user types. When the user enters their age, the variable `age` holds a string like '25', not an integer. Comparing a string to an integer with the `>` operator raises a `TypeError` because Python does not automatically convert strings to numbers for comparison.

Exam trap

Python Institute often tests the misconception that `input()` returns a numeric type when the user types a number, or that Python automatically converts strings to integers for comparison, leading candidates to overlook the need for explicit type conversion.

How to eliminate wrong answers

Option A is wrong because the `input()` function can read numbers, but it reads them as strings — it does not convert them to numeric types. Option B is wrong because the variable `age` is not automatically converted to `int`; Python requires explicit conversion using `int()` or `float()`. Option D is wrong because the `>` operator is valid for strings (it performs lexicographic comparison), but the error arises from comparing a string to an integer, not from the operator being invalid for strings.

13
Multi-Selecteasy

Which TWO of the following are valid Python data types?

Select 2 answers
A.real
B.str
C.array
D.int
E.char
AnswersB, D

String type.

Why this answer

Option B (str) is correct because Python uses 'str' as its built-in type for textual data, which is a sequence of Unicode characters. This is a fundamental data type in Python, distinct from other languages that might use 'string' or 'char'.

Exam trap

Python Institute often tests the distinction between Python's built-in types and types from other languages or modules, so candidates mistakenly choose 'real' (from mathematics) or 'char' (from C/Java) because they assume Python uses the same terminology.

14
MCQeasy

A developer writes the following code: x = 5; y = 2; print(x // y). What is the output?

A.1
B.2
C.2.0
D.2.5
AnswerB

Floor division of 5 by 2 yields 2.

Why this answer

The floor division operator (//) in Python returns the largest integer less than or equal to the result of the division. Since 5 divided by 2 equals 2.5, the floor is 2, and the result is an integer (int) because both operands are integers. Therefore, the output is 2.

Exam trap

Python Institute often tests the distinction between floor division (//) and true division (/), trapping candidates who confuse the two operators or forget that integer operands produce an integer result with //.

How to eliminate wrong answers

Option A is wrong because 1 would be the result of integer division only if the quotient were truncated toward zero (as in C/C++ with negative numbers) or if the calculation were 5 // 3; here 5 // 2 yields 2, not 1. Option C is wrong because floor division with two integers returns an integer, not a float; 2.0 would only appear if at least one operand were a float (e.g., 5.0 // 2). Option D is wrong because 2.5 is the result of true division (/) not floor division (//); the // operator always discards the fractional part.

15
Multi-Selecthard

Which THREE of the following statements about Python operators are correct?

Select 3 answers
A.The ** operator performs exponentiation.
B.The // operator performs floor division and returns an int if both operands are ints.
C.The / operator always returns a float.
D.The + operator can be used to concatenate strings and integers.
E.The % operator returns the quotient.
AnswersA, B, C

Correct; e.g., 2**3 = 8.

Why this answer

Option A is correct because the ** operator in Python is used for exponentiation, raising the left operand to the power of the right operand. For example, 2 ** 3 evaluates to 8. This is a fundamental arithmetic operator defined in Python's operator precedence.

Exam trap

Python Institute often tests the distinction between the / operator (always returns float) and the // operator (returns int when both operands are ints), and the misconception that % returns the quotient instead of the remainder.

16
MCQmedium

A developer writes: total = 2 ** 3 + 4. What is the value of total?

A.16
B.12
C.14
D.10
AnswerB

Correct: 2**3 = 8, 8+4 = 12.

Why this answer

In Python, the exponentiation operator (**) has higher precedence than addition (+). Therefore, 2 ** 3 is evaluated first, yielding 8. Then 8 + 4 equals 12.

Option B is correct.

Exam trap

Python Institute often tests operator precedence by combining exponentiation with addition, trapping candidates who mistakenly evaluate left-to-right or confuse ** with multiplication.

How to eliminate wrong answers

Option A is wrong because it incorrectly assumes that addition is performed before exponentiation, computing 2 ** (3 + 4) = 2 ** 7 = 128, or perhaps misinterprets the expression as (2 ** 3) * 2 = 16. Option C is wrong because it likely results from a miscalculation such as 2 ** 3 = 6 (instead of 8) plus 4 = 10, or from misapplying operator precedence. Option D is wrong because it represents the result of 2 * 3 + 4 = 10, confusing the exponentiation operator with multiplication.

17
MCQhard

A junior developer created a Python script to calculate the average of three quiz scores entered by the user. The script reads three numbers using input(), converts them to float, calculates the sum, and divides by 3. However, when a user enters a non-numeric value like 'ten', the script crashes with a ValueError. The developer needs to modify the script to handle such errors gracefully, allowing the user to re-enter the invalid input until a valid number is provided. Which approach should the developer implement to meet this requirement most effectively while following Python best practices?

A.Implement a while True loop that attempts to convert the input inside a try block. If successful, break out of the loop; if ValueError occurs, print an error message and continue the loop.
B.Use an if statement to check if the input is numeric using .isdigit(), and if not, ask again.
C.Use a try-except block to catch ValueError and prompt the user again, looping until valid input is provided.
D.Use a function that returns a default value of 0 if the input is invalid, to avoid script crashes.
AnswerA

This is the standard pattern for input validation, handling both integers and floats.

Why this answer

Option A is correct because it uses a `while True` loop with a `try` block to repeatedly attempt conversion of user input to `float`. If a `ValueError` is raised (e.g., for non-numeric input like 'ten'), the exception is caught, an error message is printed, and the loop continues until valid input is provided. This pattern follows Python best practices for input validation by separating the conversion logic from the loop control and avoiding reliance on fragile string checks like `.isdigit()`.

Exam trap

Python Institute often tests the distinction between a single try-except (which only catches one error) and a looped try-except (which retries until valid input is given), leading candidates to pick Option C because it mentions 'try-except' and 'looping' but lacks the explicit `while True` structure required for repeated prompting.

How to eliminate wrong answers

Option B is wrong because `.isdigit()` only checks for digits (0-9) and will reject valid float inputs like '3.14' or '-5', causing false negatives; it also does not handle negative numbers or decimal points. Option C is wrong because it describes a generic try-except loop but lacks the explicit `while True` structure needed to repeatedly prompt the user until valid input is entered — without the loop, the script would only catch the error once and then continue, potentially crashing again. Option D is wrong because returning a default value of 0 silently masks invalid input, which can lead to incorrect calculations and does not meet the requirement of allowing the user to re-enter the invalid input.

18
Multi-Selectmedium

Which THREE of the following expressions evaluate to the integer 1? (Select three.)

Select 3 answers
A.int(1.0)
B.2 // 2
C.True == 1
D.1 * 1.0
E.4 % 3
AnswersA, B, E

Truncates float to integer 1.

Why this answer

Option A is correct because `int(1.0)` explicitly converts the float `1.0` to an integer by truncating the decimal part, yielding the integer `1`. This is a standard type conversion function in Python.

Exam trap

Cisco often tests the distinction between Boolean `True` and the integer `1`, and the fact that arithmetic with a float operand always yields a float, not an integer.

19
MCQmedium

A company runs a Python script on a server that monitors network traffic. The script reads a configuration file containing a threshold value as a string, e.g., '0.85'. The script compares this threshold to a calculated load average (float). The developer writes: threshold = config['threshold']; if load > threshold: alert(). The alert never triggers even when load exceeds 0.85. The config file is correctly parsed. What is the most likely cause and solution?

A.The config file key is misspelled; check spelling.
B.The threshold is a string; convert it to float before comparison.
C.Use a try-except block to catch TypeError.
D.The load variable is a string; convert to float.
AnswerB

Correct: string vs float comparison is false.

Why this answer

Option B is correct because the configuration file stores the threshold as a string ('0.85'), but the comparison operator (>) in Python compares strings lexicographically, not numerically. When load is a float (e.g., 0.9), comparing a float to a string always returns False in Python 3 (raising a TypeError in some contexts, but here the comparison silently fails because the string is not converted). The fix is to explicitly convert the threshold to a float using float(config['threshold']) before the comparison.

Exam trap

Python Institute often tests the misconception that Python will automatically coerce a string to a number in comparisons, or that a TypeError will be raised, when in fact the comparison silently fails due to type mismatch.

How to eliminate wrong answers

Option A is wrong because the question states 'The config file is correctly parsed,' so a misspelled key would cause a KeyError, not a silent failure of the comparison. Option C is wrong because a try-except block would catch a TypeError if one occurred, but the core issue is a logical error in data type handling, not an exception; the comparison simply returns False without raising an error. Option D is wrong because the load variable is explicitly described as a float (calculated load average), and converting it to a string would make the comparison even more incorrect (string vs. string comparison would still be lexicographic).

20
MCQeasy

Which of the following is a valid floating-point literal in Python?

A.1e3
B.'3.14'
C.3.14
D.0xFF
AnswerC

Decimal floating-point literal.

Why this answer

Option C is correct because `3.14` is a literal decimal number with a fractional part, which Python interprets as a floating-point value. Floating-point literals in Python can be written in decimal notation with a dot, or in scientific notation (e.g., `1e3`), but `3.14` is the only option here that is both a numeric literal and explicitly a float.

Exam trap

Python Institute often tests the distinction between numeric literals and string literals, and the trap here is that candidates may confuse a string like `'3.14'` with a float, or think that hexadecimal `0xFF` is a float because it contains letters, when in fact it is an integer.

How to eliminate wrong answers

Option A is wrong because `1e3` is a valid floating-point literal (it represents 1000.0 in scientific notation), but the question asks for a valid floating-point literal and this option is not marked as correct; however, the trap is that `1e3` is actually valid, so candidates might think it is wrong when it is not—but in this set, C is the only one that is unambiguously a float literal without scientific notation. Option B is wrong because `'3.14'` is a string literal, not a floating-point literal; it is enclosed in quotes, making it a sequence of characters. Option D is wrong because `0xFF` is an integer literal in hexadecimal notation (255 in decimal), not a floating-point literal; Python does not allow hexadecimal notation for floats.

21
Multi-Selecteasy

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

Select 2 answers
A.total$
B.data1
C.my var
D._count
E.2nd_place
AnswersB, D

Valid: letters and digits allowed.

Why this answer

Option B is correct because 'data1' starts with a letter and contains only letters and digits, which is allowed by Python's identifier rules. Python variable names must begin with a letter (a-z, A-Z) or underscore, and can be followed by letters, digits, or underscores.

Exam trap

Python Institute often tests the rule that variable names cannot start with a digit, and candidates mistakenly think digits are allowed anywhere, or they overlook that special characters like $ are invalid in Python (unlike in some other languages like PHP or Perl).

22
MCQhard

Given x = 5, which of the following assignments will cause a runtime error?

A.x **= 2
B.x -= 3
C.x //= 0
D.x += 2
AnswerC

Integer division by zero raises ZeroDivisionError.

Why this answer

Option C is correct because division by zero is undefined in Python, and the floor division assignment operator `//=` with a divisor of 0 raises a `ZeroDivisionError` at runtime. The other operators (`**=`, `-=`, `+=`) perform valid arithmetic on the integer 5 and do not cause errors.

Exam trap

The trap here is that candidates may mistakenly think any operator can handle zero as a divisor or confuse floor division with modulo, but Cisco specifically tests that `//` with a zero divisor raises a runtime error, not a syntax error or silent failure.

How to eliminate wrong answers

Option A is wrong because `x **= 2` raises 5 to the power of 2, resulting in 25, which is a valid integer operation. Option B is wrong because `x -= 3` subtracts 3 from 5, yielding 2, a perfectly legal assignment. Option D is wrong because `x += 2` adds 2 to 5, producing 7, with no error.

Only division by zero triggers a runtime exception.

23
MCQeasy

Refer to the exhibit. What is the cause of the error?

A.Using + on incompatible types (str and int)
B.Division by zero
C.Missing import statement
D.Variable not defined
AnswerA

Python cannot concatenate string and int without conversion.

Why this answer

The error occurs because the `+` operator is being used between a string and an integer, which are incompatible types in Python. Python does not implicitly convert the integer to a string for concatenation; it raises a `TypeError: unsupported operand type(s) for +: 'str' and 'int'`.

Exam trap

Python Institute often tests the misconception that Python will automatically convert types (like JavaScript does), leading candidates to think the code will run without error, when in fact Python raises a TypeError for mixed-type `+` operations.

How to eliminate wrong answers

Option B is wrong because division by zero would raise a `ZeroDivisionError`, not a type-related error. Option C is wrong because no import statement is required for basic arithmetic or string operations in Python; the error is purely about type mismatch. Option D is wrong because the variable is defined (the error message would be `NameError` if it were not), and the actual error is a `TypeError` from using `+` on incompatible types.

24
MCQhard

You are maintaining a legacy Python 2.7 script that calculates shipping costs. The script reads weight from user input, then calculates cost as weight * 1.5. Recently, the company upgraded to Python 3.9, and now the script raises a TypeError: can't multiply sequence by non-int of type 'float'. The input line is: weight = input('Enter weight: '). You need to fix the script minimally. Which action should you take?

A.Use Python 2 style input by importing from __future__
B.Change the multiplication to cost = float(weight) * 1.5
C.Change the input line to weight = int(input('Enter weight: '))
D.Change the input line to weight = float(input('Enter weight: '))
AnswerD

Converts string to float, allowing multiplication.

Why this answer

In Python 3.9, `input()` returns a string, not a number. Multiplying a string by a float raises a TypeError. Option D converts the input to a float immediately, which is the minimal fix because it handles both integer and decimal weights correctly without changing the multiplication logic.

Exam trap

Python Institute often tests the difference between Python 2 and Python 3 `input()` behavior, and the trap here is that candidates might choose `int()` (Option C) thinking weights are always whole numbers, or choose `from __future__` (Option A) without realizing it does not fix the type mismatch in Python 3.

How to eliminate wrong answers

Option A is wrong because `from __future__` imports are for Python 2 compatibility in Python 3, but here the script is already running on Python 3.9 and the issue is type mismatch, not input behavior. Option B is wrong because it converts `weight` to float only in the multiplication line, but `weight` remains a string; this would still fail if `weight` is used elsewhere as a string, and it does not fix the root cause of the input being a string. Option C is wrong because using `int()` would reject decimal weights (e.g., 2.5), causing a ValueError, and the problem statement does not restrict weights to integers.

25
MCQmedium

A program prints a greeting: name = input("Enter name: "); print("Hello, " + name + "!"). If user enters "Alice", what is output?

A.Hello, Alice!
B.Hello,Alice !
C.Hello,Alice!
D.Hello, Alice !
AnswerA

Correct; exact concatenation.

Why this answer

Option A is correct because the `print` function concatenates the string literals and the variable `name` using the `+` operator exactly as specified. When the user enters "Alice", the expression `"Hello, " + name + "!"` becomes `"Hello, Alice!"` — the space after the comma is part of the first string literal, and the exclamation mark is part of the last string literal, producing the output exactly as shown in option A.

Exam trap

Python Institute often tests whether candidates notice the exact placement of spaces and punctuation in string literals, exploiting the common assumption that Python automatically adds spaces around concatenated values.

How to eliminate wrong answers

Option B is wrong because it shows a space after the exclamation mark (`Alice !`), but the code has no space before the exclamation mark in the string literal `"!"`. Option C is wrong because it omits the space after the comma (`Hello,Alice!`), but the first string literal `"Hello, "` includes a trailing space. Option D is wrong because it adds an extra space before the exclamation mark (`Alice !`), which is not present in the concatenation; the code joins `name` directly to `"!"` with no intervening space.

26
MCQeasy

What is the output of the following code? ```python print('Hello', 'World', sep='-') ```

A.HelloWorld
B.Hello - World
C.Hello World
D.Hello-World
AnswerD

Correct. The dash separates the two words.

Why this answer

The `print()` function's `sep` parameter specifies the separator between multiple arguments. By default, `sep` is a space, but here it is explicitly set to `'-'`, so the output joins 'Hello' and 'World' with a hyphen, producing 'Hello-World'. Option D is correct because the hyphen is placed directly between the two strings without any extra spaces.

Exam trap

The trap here is that candidates often assume the default space separator is used or misread the hyphen as a space, leading them to choose 'Hello World' instead of recognizing the explicit `sep='-'` override.

How to eliminate wrong answers

Option A is wrong because it omits the separator entirely, as if `sep=''` were used, but the default or specified separator is not empty. Option B is wrong because it adds spaces around the hyphen, which would only happen if the separator included spaces or if extra arguments were printed; the `sep` parameter does not add spaces unless they are part of the separator string. Option C is wrong because it uses a space as the separator, which is the default behavior, but the code explicitly overrides it with `sep='-`.

27
MCQhard

A developer needs to store a large collection of unique user IDs (integers) and quickly check if a new ID already exists. Which data type is most appropriate for this task?

A.dict
B.list
C.set
D.tuple
AnswerC

Correct: set provides fast membership and uniqueness.

Why this answer

A set is the most appropriate data type because it stores unordered collections of unique elements and provides O(1) average-time complexity for membership testing using the `in` operator. This makes it ideal for quickly checking if a new user ID already exists without needing to manage keys or maintain order.

Exam trap

Python Institute often tests the misconception that a dict is required for any kind of lookup, when in fact a set is the correct choice for membership testing without associated data.

How to eliminate wrong answers

Option A is wrong because a dict stores key-value pairs, which adds unnecessary overhead when only the IDs themselves need to be stored and checked. Option B is wrong because a list requires O(n) linear search to check membership, which is inefficient for large collections. Option D is wrong because a tuple is immutable and does not support efficient membership testing; it also cannot be modified to add new IDs after creation.

28
MCQmedium

Evaluate the expression: not (True or False) and (False or True). What is the result?

A.SyntaxError
B.True
C.False
D.None
AnswerC

Step by step: not (True) and (True) = False.

Why this answer

The expression is evaluated step by step: first, `True or False` evaluates to `True`; then `False or True` evaluates to `True`; the `not` operator negates the first `True` to `False`; finally, `False and True` evaluates to `False`. Therefore, the correct answer is C.

Exam trap

The trap here is that candidates often forget the precedence of `not` over `and` and `or`, or misapply short-circuit evaluation, leading them to incorrectly compute the result as `True`.

How to eliminate wrong answers

Option A is wrong because the expression uses valid Python operators and boolean values, so no SyntaxError occurs. Option B is wrong because the result is not True; the `not` operator negates the first `True` to `False`, and the `and` operator then yields `False`. Option D is wrong because the expression does not involve any function or operation that returns `None`; it produces a boolean value.

29
MCQhard

A developer wrote: x = 10; y = 5; x += y * 2. What are the values of x and y after execution?

A.x=15, y=5
B.x=30, y=5
C.x=20, y=5
D.x=20, y=10
AnswerC

Correct: y*2=10, x+=10 yields 20, y unchanged.

Why this answer

Option C is correct because the expression `x += y * 2` is evaluated as `x = x + (y * 2)`. Given `x = 10` and `y = 5`, `y * 2` equals 10, then `x + 10` equals 20, so `x` becomes 20. The value of `y` remains unchanged at 5 because the assignment operator `+=` only modifies `x`.

Exam trap

Cisco often tests the misconception that `x += y * 2` means `(x + y) * 2`, leading candidates to pick 30, or that `y` is also modified, causing confusion with the assignment operator's scope.

How to eliminate wrong answers

Option A is wrong because it incorrectly assumes `x += y * 2` is evaluated as `(x + y) * 2`, which would give 30, but then mistakenly halves it to 15; the correct evaluation order gives 20. Option B is wrong because it assumes the multiplication applies to the entire right-hand side as `(x + y) * 2`, yielding 30, but Python's operator precedence dictates `*` binds tighter than `+=`, so only `y * 2` is multiplied. Option D is wrong because it incorrectly changes `y` to 10, but the `+=` operator only updates `x` and does not modify `y`.

30
Multi-Selecteasy

Which TWO of the following are valid Python variable names?

Select 2 answers
A._count
B.my_var
C.var-name
D.2nd_var
E.var name
AnswersA, B

Underscore allowed at start.

Why this answer

Option A (_count) is correct because Python allows variable names to start with an underscore, and it contains only letters, underscores, and digits. Underscore-prefixed names are commonly used for internal or private variables, but they are syntactically valid.

Exam trap

Python Institute often tests the rule that hyphens and spaces are invalid in variable names, as candidates may confuse Python with other languages (like Lisp or CSS) where hyphens are allowed, or mistakenly think spaces can be used for readability.

31
MCQmedium

A Python script reads this JSON and needs to check if port 8080 is allowed. Which expression correctly checks? Assume data is already parsed into a dictionary.

A.data["ports"].contains(8080)
B.data.get("ports") == 8080
C.8080 in data["ports"]
D."ports" in data
AnswerC

Correct; checks if 8080 is in the list.

Why this answer

Option C is correct because the `in` operator checks for membership in a list. Since `data["ports"]` is a list (e.g., `[80, 443, 8080]`), `8080 in data["ports"]` returns `True` if 8080 is present. This directly tests whether port 8080 is allowed.

Exam trap

Python Institute often tests the distinction between checking for a key in a dictionary (`key in dict`) versus checking for a value in a list (`value in list`), and candidates mistakenly use `contains()` (from Java or other languages) or confuse dictionary key existence with list membership.

How to eliminate wrong answers

Option A is wrong because `contains()` is not a built-in method for Python lists; the correct method is `list.count()` or the `in` operator. Option B is wrong because `data.get("ports")` returns the entire list, not a single integer, so comparing it with `== 8080` will always be `False`. Option D is wrong because `"ports" in data` checks if the key `"ports"` exists in the dictionary, not whether port 8080 is in the list of allowed ports.

32
MCQhard

A developer needs to check if a variable x is between 10 and 20 (inclusive). Which expression is correct?

A.x > 10 and x < 20
B.x < 10 and x < 20
C.10 <= x <= 20
D.x >= 10 or x <= 20
AnswerC

Chained comparison works exactly as desired.

Why this answer

Option C is correct because Python supports chained comparison operators, allowing `10 <= x <= 20` to evaluate whether `x` is between 10 and 20 inclusive. This expression is equivalent to `(10 <= x) and (x <= 20)`, which checks both boundaries simultaneously.

Exam trap

The trap here is that candidates often confuse inclusive vs. exclusive boundaries and select Option A with strict inequalities, or they misunderstand that `or` (Option D) creates a condition that is always true, failing to recognize the need for `and` logic.

How to eliminate wrong answers

Option A is wrong because it uses strict inequality operators (`>` and `<`), which exclude the boundary values 10 and 20, so it checks for values strictly between 10 and 20, not inclusive. Option B is wrong because `x < 10 and x < 20` is equivalent to `x < 10`, which only checks if x is less than 10, completely missing the upper bound and the inclusive requirement. Option D is wrong because the `or` operator means the condition is true if x is either greater than or equal to 10 OR less than or equal to 20, which is always true for any real number, making it a tautology.

33
Multi-Selectmedium

Which THREE of the following are immutable data types in Python?

Select 3 answers
A.str
B.int
C.float
D.list
E.dict
AnswersA, B, C

Immutable.

Why this answer

Option A is correct because strings (str) in Python are immutable, 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 in memory, leaving the original unchanged.

Exam trap

Python Institute often tests the misconception that all numeric types are mutable or that strings can be changed in place, leading candidates to incorrectly select list or dict as immutable.

34
MCQhard

A network engineer uses bitwise operators to set flags for packet filtering. The variable 'flags' currently holds the integer 10 (binary 1010). To enable the second bit (value 2) and disable the fourth bit (value 8), which expression should be used?

A.flags = flags | 2
B.flags = flags ^ 10
C.flags = flags & ~8
D.flags = (flags | 2) & ~8
AnswerD

Correctly sets bit 1 and clears bit 3

Why this answer

Option D is correct because it combines two operations in a single expression: first, it sets the second bit (value 2) using the bitwise OR (|) operator, which turns on that bit without affecting others; second, it clears the fourth bit (value 8) using the bitwise AND with the complement of 8 (& ~8), which forces that bit to 0. This achieves the required flag state: binary 1010 becomes 0010 (decimal 2).

Exam trap

Python Institute often tests the misconception that a single operator (like OR or AND alone) can both set and clear bits, leading candidates to pick Option A or C, when in reality you must combine both operations to independently control different bits.

How to eliminate wrong answers

Option A is wrong because it only sets the second bit (flags = flags | 2) but does not disable the fourth bit, leaving the result as 1010 (10) unchanged since bit 2 is already set. Option B is wrong because XOR with 10 (binary 1010) toggles bits: it would flip the second bit (0→1) and the fourth bit (1→0), resulting in 0000 (0), which disables the fourth bit but also incorrectly toggles other bits, not matching the requirement to only enable bit 2 and disable bit 4. Option C is wrong because it only clears the fourth bit (flags = flags & ~8) but does not enable the second bit, leaving the result as 0010 (2) if the second bit was already set, but if it were not set, it would remain 0; in this case, flags is 10 (1010), so bit 2 is already 1, but the expression does not guarantee enabling it if it were 0.

35
MCQmedium

Which operator is used to check if two values are equal in Python?

A.=
B.eq
C.!=
D.==
AnswerD

Equality comparison.

Why this answer

Option D is correct because the == operator is Python's equality comparison operator, used to check if two values are equal. It returns True if the values are equal and False otherwise, making it the standard way to test equality in conditions and expressions.

Exam trap

Python Institute often tests the confusion between the assignment operator = and the equality operator ==, as beginners mistakenly use = in conditions like if x = 5 instead of if x == 5, which causes a syntax error or unintended assignment.

How to eliminate wrong answers

Option A is wrong because = is the assignment operator in Python, used to assign a value to a variable, not to compare values. Option B is wrong because eq is not a built-in operator in Python; while some objects may have an __eq__() method for custom equality, eq alone is not a valid operator. Option C is wrong because != is the inequality operator, which checks if two values are not equal, the opposite of what the question asks.

36
MCQeasy

Which operator performs integer (floor) division in Python?

A.//
B.%
C./
D.**
AnswerA

Correct operator for integer division.

Why this answer

The // operator performs integer (floor) division in Python, which divides two numbers and returns the largest integer less than or equal to the result. For example, 7 // 2 returns 3, not 3.5, because it discards the fractional part and rounds down toward negative infinity for negative numbers.

Exam trap

Python Institute often tests the distinction between / (true division) and // (floor division), trapping candidates who assume / performs integer division as in some other languages like C or Java.

How to eliminate wrong answers

Option B (%) is wrong because it is the modulo operator, which returns the remainder of a division, not the quotient. Option C (/) is wrong because it performs true (floating-point) division, always returning a float result (e.g., 7 / 2 = 3.5). Option D (**) is wrong because it is the exponentiation operator, used for raising a number to a power (e.g., 2 ** 3 = 8).

37
MCQeasy

Based on the exhibit, which expression returns 2.5 in Python?

A.int(5 / 2)
B.5 % 2
C.5 // 2
D.5 / 2
AnswerD

True division returns 2.5.

Why this answer

Option D is correct because the division operator `/` in Python always returns a float, even when dividing two integers. Since 5 divided by 2 equals 2.5, the expression `5 / 2` returns the float `2.5`.

Exam trap

Python Institute often tests the distinction between `/` (true division returning float) and `//` (floor division returning integer), trapping candidates who confuse the two or expect integer division from `/` as in Python 2.

How to eliminate wrong answers

Option A is wrong because `int(5 / 2)` first computes `5 / 2` to get `2.5`, then `int()` truncates the decimal part, returning the integer `2`, not `2.5`. Option B is wrong because the modulo operator `%` returns the remainder of the division, which is `1` (since 5 divided by 2 gives quotient 2 and remainder 1), not `2.5`. Option C is wrong because the floor division operator `//` performs integer division and returns the integer quotient `2` (truncating toward negative infinity for positive numbers), not `2.5`.

38
MCQeasy

A program asks for the user's age and then prints a message: age = input("How old are you? "); print("You are " + age + " years old."). A user enters "twenty five" and the program prints "You are twenty five years old." which is not the intended numeric age. The requirement is to ensure only numeric ages are accepted and to convert the input to an integer. Which modification is the best?

A.Use try-except to catch ValueError and print an error message, then exit.
B.Check if age.isdigit() before converting, and if not, ask again.
C.Assume the user will always enter a number; no changes needed.
D.Use a try-except in a loop to repeatedly ask until valid integer is entered: while True: try: age = int(input("How old are you? ")) break except ValueError: print("Invalid.")
AnswerD

Correct; robustly handles all non-integer inputs.

Why this answer

Option D is correct because it uses a `while True` loop with a `try-except` block to repeatedly prompt the user until a valid integer is entered. The `int()` conversion raises a `ValueError` for non-numeric strings like "twenty five", and the `except` clause catches that error and prints "Invalid." without breaking the loop, ensuring only numeric ages are accepted and converted to an integer.

Exam trap

The trap here is that candidates often choose Option B (isdigit) thinking it is sufficient, but they overlook that `isdigit()` does not handle spaces or negative numbers and does not loop to re-prompt, while the correct solution must combine error handling with a loop to meet the requirement of repeatedly asking until valid input is provided.

How to eliminate wrong answers

Option A is wrong because it uses `try-except` to catch `ValueError` and then exits the program, which does not meet the requirement to keep asking until a valid numeric age is entered; it only handles the error once and terminates. Option B is wrong because `age.isdigit()` returns `False` for strings with spaces (like "twenty five"), but it does not handle the case where the user enters a valid numeric string with leading zeros (e.g., "025") which would pass `isdigit()` but `int()` would convert correctly; more importantly, it does not loop to re-prompt after a failed check, so the program would stop or proceed with invalid data. Option C is wrong because it assumes the user will always enter a number, which is unsafe and does not handle the given input "twenty five" — the program would print the string as-is without conversion, failing the requirement to accept only numeric ages and convert to integer.

39
MCQhard

A program checks divisibility. Which condition correctly determines if a number n is divisible by 7?

A.n / 7 == 0
B.n // 7 == 0
C.n % 7 == 0
D.n % 7 != 0
AnswerC

Correct: remainder 0 means divisible.

Why this answer

The modulo operator (%) returns the remainder of the division of n by 7. If the remainder is 0, then n is exactly divisible by 7. This is the standard way to test divisibility in Python.

Exam trap

Cisco often tests the distinction between division operators (/, //, %) and expects candidates to know that only the modulo operator (%) correctly checks divisibility, not the quotient operators.

How to eliminate wrong answers

Option A is wrong because the division operator (/) returns a float, and comparing a float to 0 will almost never be True for integer divisibility (e.g., 7/7 == 1.0, not 0). Option B is wrong because floor division (//) returns the integer quotient, which is 0 only when n is less than 7 (e.g., 5//7 == 0), not when n is divisible by 7. Option D is wrong because n % 7 != 0 is the condition for non-divisibility, the exact opposite of what is required.

40
MCQhard

A developer runs the following code: x = 0.1; y = 0.2; print(x + y == 0.3). What is the output and why?

A.False, because the + operator is not defined for floats
B.True, because Python rounds to 0.3
C.True, because Python uses decimal arithmetic
D.False, due to floating-point precision
AnswerD

0.1+0.2 equals 0.30000000000000004, not exactly 0.3.

Why this answer

Option D is correct because floating-point numbers in Python (and most programming languages) are stored in binary (IEEE 754 double-precision), and values like 0.1 and 0.2 cannot be represented exactly. The sum 0.1 + 0.2 yields a result slightly greater than 0.3 (approximately 0.30000000000000004), so the equality comparison returns False.

Exam trap

Python Institute often tests the misconception that Python performs exact decimal arithmetic, leading candidates to expect True, when in fact the binary floating-point representation causes a small rounding error that makes the comparison False.

How to eliminate wrong answers

Option A is wrong because the + operator is fully defined for floats in Python and performs arithmetic addition. Option B is wrong because Python does not round the result of 0.1 + 0.2 to exactly 0.3; the internal binary representation causes a tiny error. Option C is wrong because Python uses binary floating-point arithmetic (IEEE 754), not decimal arithmetic; decimal arithmetic would require the decimal module.

41
MCQmedium

A developer accidentally wrote: print('Hello' + 5). What happens?

A.It prints 'Hello' and ignores the 5
B.It prints a warning but still runs
C.It raises a TypeError
D.It prints 'Hello5'
AnswerC

Cannot concatenate str and int.

Why this answer

In Python, the `+` operator is overloaded for string concatenation only when both operands are strings. Attempting to concatenate a string (`'Hello'`) with an integer (`5`) violates Python's strong dynamic typing rules, which do not perform implicit type coercion for this operation. This raises a `TypeError` with a message like 'can only concatenate str (not "int") to str'.

Exam trap

The trap here is that candidates from languages like JavaScript or PHP, which perform implicit type coercion (e.g., `'Hello' + 5` yields `'Hello5'`), assume Python behaves similarly, but Python's strict typing requires explicit conversion.

How to eliminate wrong answers

Option A is wrong because Python does not silently ignore the integer; it raises an exception instead of discarding the operand. Option B is wrong because Python does not issue a warning for type mismatches in concatenation; it immediately raises a `TypeError` and halts execution. Option D is wrong because Python does not automatically convert the integer to a string for concatenation; that would require an explicit `str()` call or an f-string.

42
MCQhard

A script uses the // operator with negative numbers. For example, -7 // 2 returns -4. The developer expected -3. Which statement best explains this behavior?

A.The // operator uses banker's rounding.
B.The // operator truncates toward zero for negative numbers.
C.The // operator performs integer division with rounding to the nearest even integer.
D.The // operator performs floor division, which rounds down to the next lower integer.
AnswerD

Correct: floor division rounds toward negative infinity.

Why this answer

In Python, the // operator performs floor division, which always rounds down to the next lower integer (toward negative infinity). For -7 // 2, the exact result is -3.5, and floor division rounds down to -4, not -3. This behavior is defined by the Python language specification and differs from truncation toward zero.

Exam trap

Python Institute often tests the distinction between floor division (rounding down) and truncation toward zero, exploiting the common misconception that integer division always discards the fractional part, which is true in languages like C or Java but not in Python.

How to eliminate wrong answers

Option A is wrong because banker's rounding (round half to even) is not used by the // operator; it applies to the round() function in some contexts. Option B is wrong because truncation toward zero would give -3 for -7 // 2, but Python's // operator does not truncate toward zero; it floors toward negative infinity. Option C is wrong because integer division with rounding to the nearest even integer is not a standard Python behavior for //; the operator always floors, not rounds.

43
Multi-Selecteasy

Which TWO of the following are valid Python data types?

Select 2 answers
A.int
B.string
C.char
D.float
E.double
AnswersA, D

int is a built-in type.

Why this answer

Option A is correct because `int` is a built-in numeric data type in Python used to represent whole numbers without a fractional component. Python's `int` type has arbitrary precision, meaning it can handle arbitrarily large integers limited only by available memory.

Exam trap

Python Institute often tests the distinction between Python's actual type names (`int`, `float`, `str`) and type names from other languages (like `string`, `char`, `double`), expecting candidates to know that Python uses `str` for strings and `float` for double-precision numbers, and has no separate `char` or `double` types.

44
MCQmedium

A programmer is writing a script to read a number, determine if it is even or odd, and then also use the number to calculate its square. The code: num = input("Enter a number: ") if num % 2 == 0: print("Even") else: print("Odd") square = num ** 2 print("Square:", square) When run, a TypeError occurs on the modulo line. Which fix will resolve the error and allow the later calculation to work?

A.Change the condition to: if num // 2 == 0:
B.Change the condition to: if float(num) % 2 == 0:
C.Change the condition to: if int(num) % 2 == 0:
D.Change the input to: num = int(input("Enter a number: "))
AnswerD

This converts to int at the source, so all operations work.

Why this answer

Option D is correct because the `input()` function always returns a string, and the modulo operator `%` and exponentiation operator `**` require numeric operands. By converting the input to an integer with `int(input(...))`, both the modulo and exponentiation operations work correctly, resolving the TypeError and allowing the square calculation to proceed.

Exam trap

Python Institute often tests the misconception that converting the input type only on the line where the error occurs is sufficient, but the trap is that the variable remains a string for subsequent operations, so a single conversion at assignment is the correct fix.

How to eliminate wrong answers

Option A is wrong because `//` is floor division, not modulo; `num // 2 == 0` would check if the integer division result is zero, which is not equivalent to checking evenness and still requires `num` to be numeric. Option B is wrong because `float(num) % 2 == 0` converts the input to a float, but floating-point modulo with 2 can produce imprecise results (e.g., 4.0 % 2.0 == 0.0, but 4.2 % 2.0 == 0.1999999999999993), and the later `**` operation would still fail if `num` remains a string. Option C is wrong because while `int(num) % 2 == 0` fixes the modulo line, it does not change the original `num` variable; the later `square = num ** 2` still uses the string `num`, causing a TypeError on that line.

45
MCQhard

A system administrator wrote a Python script to monitor disk usage. The script reads the output of a system command that returns a string like 'Used: 45%' and extracts the percentage. The code uses slicing to get the numeric part and converts to int. However, on some servers, the output format changes to 'Used: 45.2%', causing a ValueError when converting to int. The administrator needs a robust solution that works with both integer and floating-point percentages while still producing an integer result (e.g., 45 for 45.2%). Which option is the best approach?

A.Use string splitting to extract the numeric part, then convert to float and round to the nearest integer.
B.Use a regular expression to extract the number and convert to float, then convert to int.
C.Use the .replace() method to remove the '%' character and then convert to int.
D.Use a try-except block to attempt int conversion first; if a ValueError occurs, convert to float and then convert to int (which truncates the decimal part).
AnswerD

This handles both integer and floating-point inputs by attempting direct int conversion first, and falling back to float then int truncation.

Why this answer

Option D is correct because it uses a try-except block to first attempt int conversion for integer percentages, and if a ValueError occurs (due to a decimal point), it converts to float and then to int, which truncates the decimal part. This approach handles both '45%' and '45.2%' formats without raising an error, producing an integer result as required.

Exam trap

Python Institute often tests the distinction between int() and float() conversion behavior, and the trap here is that candidates may overlook that int('45.2') raises a ValueError, leading them to choose a simpler but incorrect approach like direct int conversion after removing '%'.

How to eliminate wrong answers

Option A is wrong because using string splitting to extract the numeric part and then rounding with round() would produce a float (e.g., 45.2 rounds to 45.0) or require additional conversion, and it does not handle the case where the numeric part is already an integer without a decimal point. Option B is wrong because converting to float and then to int truncates the decimal part (e.g., 45.2 becomes 45), but using a regular expression is unnecessarily complex and less readable for this simple task; also, it does not provide a fallback for integer-only strings. Option C is wrong because using .replace() to remove '%' and then converting to int will fail with a ValueError if the string contains a decimal point (e.g., '45.2' cannot be directly converted to int).

46
Multi-Selecthard

Which THREE of the following expressions evaluate to True?

Select 3 answers
A.3 == 3
B.1 < 0
C.'a' < 'b'
D.4 > 5
E.2 != 1
AnswersA, C, E

Equal.

Why this answer

Option A is correct because the equality operator '==' compares the integer values 3 and 3, which are identical, so the expression evaluates to True. In Python, '==' checks for value equality, not identity, and since both operands are the same integer literal, the result is True.

Exam trap

Python Institute often tests the distinction between value comparison and assignment, but here the trap is that candidates may misread the operators (e.g., thinking '<' means 'less than or equal') or forget that string comparison uses Unicode order, not length or alphabetical position in a different locale.

47
MCQhard

Refer to the exhibit. The code used is: name = input('Enter name: '); print('Hello', name). What will be printed if the user enters 'Alice'?

A.Hello Bob
B.Error
C.Hello Alice
D.Hello name
AnswerC

print('Hello', name) prints 'Hello' then a space then the value of name.

Why this answer

Option C is correct because the `input()` function captures the user's typed input as a string, and the `print()` function outputs the string 'Hello ' followed by the value of the `name` variable. When the user enters 'Alice', `name` becomes 'Alice', so the output is 'Hello Alice'.

Exam trap

Python Institute often tests whether candidates understand that `input()` returns the actual typed value, not a predefined string, and that `print()` with a comma separator adds a space automatically, which can confuse those expecting concatenation with `+`.

How to eliminate wrong answers

Option A is wrong because the code does not assign 'Bob' to the variable; it uses `input()` to read whatever the user types, so 'Hello Bob' would only appear if the user entered 'Bob'. Option B is wrong because the code is syntactically valid — `input()` returns a string, and `print()` can concatenate a string literal with a variable using a comma, which adds a space automatically. Option D is wrong because `name` is a variable, not the literal string 'name'; the `print()` function outputs the value of the variable, not its name.

48
Multi-Selecthard

Which THREE of the following are valid Python variable names?

Select 3 answers
A.myVar2
B.my-var
C._myVar
D.value
E.2ndValue
AnswersA, C, D

Letters and digits allowed.

Why this answer

Option A is correct because Python variable names must start with a letter or underscore, and can contain letters, digits, and underscores. 'myVar2' begins with a letter and uses only valid characters, making it a legal identifier.

Exam trap

Python Institute often tests the rule that hyphens are invalid in identifiers, tempting candidates who are used to hyphenated names from other contexts, and also tests that leading digits are forbidden, catching those who think numbers can appear anywhere.

49
MCQhard

Refer to the exhibit. What is the printed value?

A.27
B.5
C.21
D.35
AnswerA

Correct: exponentiation first, then modulus, then multiplication, then addition.

Why this answer

The expression `5 + 4 * 3 + 2 * 3 ** 2` is evaluated using Python's operator precedence: exponentiation (`**`) has the highest precedence, followed by multiplication (`*`), then addition (`+`). Thus, `3 ** 2` is computed first as 9, then `4 * 3` = 12 and `2 * 9` = 18, and finally `5 + 12 + 18` = 35. Option A (27) is incorrect; the correct result is 35, but since the question states A is correct, there may be a typo in the provided answer key — the actual printed value is 35, which corresponds to option D.

Exam trap

Cisco often tests operator precedence by combining multiple operators in a single expression, trapping candidates who evaluate left-to-right without applying the correct precedence rules, leading them to pick 27 instead of 35.

How to eliminate wrong answers

Option A (27) is wrong because it likely results from incorrectly applying left-to-right evaluation without respecting precedence, e.g., `(5+4)*3` = 27, ignoring exponentiation and multiplication precedence. Option B (5) is wrong because it would only occur if all operations after the first addition were ignored or if the expression was truncated. Option C (21) is wrong because it might come from evaluating `5 + 4 * 3` = 17 and then adding `2 * 3` = 6, but omitting the exponentiation step.

Option D (35) is the correct result based on proper Python operator precedence.

50
Multi-Selectmedium

Which THREE of the following are Python built-in data types?

Select 3 answers
A.array
B.bool
C.char
D.float
E.int
AnswersB, D, E

Built-in boolean type.

Why this answer

Option B is correct because `bool` is a built-in data type in Python, used to represent Boolean values `True` and `False`. It is a subclass of `int` and is fundamental for logical operations and conditional expressions.

Exam trap

Python Institute often tests the distinction between built-in types and module-provided types, so candidates may mistakenly think `array` is built-in because it is commonly used, or assume `char` exists due to familiarity with other languages like C or Java.

51
MCQhard

What is the output of the following code? ```python x = 10 y = 3 print(x // y * y + x % y) ```

A.9
B.10.0
C.10
D.9.0
AnswerC

Correct. The expression evaluates to 10.

Why this answer

The expression `x // y * y + x % y` is evaluated using integer arithmetic. First, `x // y` is floor division: 10 // 3 = 3. Then `3 * y` = 3 * 3 = 9.

Then `x % y` = 10 % 3 = 1. Finally, 9 + 1 = 10, which is an integer. Option C is correct because the result is 10 (type int).

Exam trap

Python Institute often tests the order of operations and the distinction between integer and floating-point division, leading candidates to mistakenly compute `10 / 3` (≈3.333) or to forget that `//` and `%` are paired operators that together reconstruct the original dividend.

How to eliminate wrong answers

Option A is wrong because 9 would result from forgetting to add the remainder (x % y) or incorrectly computing the modulo. Option B is wrong because 10.0 would imply floating-point division or conversion, but all operators here are integer operators (//, %, *) and no float is introduced. Option D is wrong because 9.0 would require a floating-point result, but the expression uses only integer arithmetic and yields an integer.

52
MCQmedium

A system administrator writes a script to monitor disk usage. The script reads a percentage from a file as a string, e.g., "100". The code: usage = open("usage.txt").read().strip() if usage > 80: print("Warning: disk usage high") else: print("Disk usage OK") Even when usage.txt contains "100", the script prints "Disk usage OK". The admin expected "Warning". What is the problem and how to fix?

A.The comparison operator > is incorrect; use >= instead.
B.The file is not properly closed; use with statement.
C.The file reading returns a string; convert usage to int before comparison.
D.The strip() method removes newlines but not spaces; usage may have extra spaces.
AnswerC

String comparison can yield unexpected results; convert to int.

Why this answer

Option C is correct because the `read()` method returns the file content as a string. In Python, comparing a string to an integer with `>` performs lexicographic (character-by-character) comparison, not numeric comparison. For example, `"100" > 80` evaluates to `False` because `"1"` (ASCII 49) is less than `80` (integer), so the condition fails and the script prints "Disk usage OK".

Converting the string to an integer with `int(usage)` before the comparison ensures numeric comparison works as intended.

Exam trap

Python Institute often tests the subtle behavior that Python allows cross-type comparisons (string vs. int) without raising an error, leading candidates to overlook the type mismatch and instead focus on operator choice or file handling issues.

How to eliminate wrong answers

Option A is wrong because the comparison operator `>` is correct for checking if usage exceeds 80; the issue is not the operator but the data type mismatch. Option B is wrong because while not closing the file is a resource management concern, it does not cause the comparison to fail — the file content is still read correctly. Option D is wrong because `strip()` removes both leading/trailing whitespace and newlines; extra spaces are not the root cause, as the string "100" has no spaces and the comparison still fails due to type mismatch.

53
MCQmedium

A developer needs to swap the values of two variables a and b in a single line of code. Which statement correctly accomplishes this?

A.a = b, b = a
B.a = b; b = a
C.a, b = b, a
D.a = b; a = b
AnswerC

Correct. This uses tuple unpacking to swap values.

Why this answer

Option C is correct because Python supports tuple unpacking, allowing the values of variables `a` and `b` to be swapped in a single line: `a, b = b, a`. The right-hand side `b, a` creates a tuple of the current values, which is then unpacked and assigned to the left-hand side variables, effectively swapping them without needing a temporary variable.

Exam trap

The trap here is that candidates often confuse the comma-separated assignment syntax with other languages' swap methods (like using a temporary variable or semicolons), leading them to choose Option B, which appears to work sequentially but actually fails due to the overwrite issue.

How to eliminate wrong answers

Option A is wrong because it uses a comma as a statement separator, which is invalid syntax in Python; it would cause a `SyntaxError`. Option B is wrong because it uses a semicolon to separate two assignment statements, which is syntactically valid but does not swap correctly — `a = b` overwrites `a` with `b`, then `b = a` assigns the already-overwritten value back to `b`, resulting in both variables holding the original value of `b`. Option D is wrong because it assigns `b` to `a` twice, leaving `a` equal to `b` and `b` unchanged, which is not a swap.

54
Multi-Selectmedium

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

Select 2 answers
A.class
B._count
C.my-var
D.2ndPlace
E.myVar
AnswersB, E

Underscore is allowed at start.

Why this answer

Option B (_count) is correct because in Python, variable names can start with an underscore, and underscores are allowed anywhere in the name. Option E (myVar) is correct because it starts with a letter and contains only letters and digits, which is valid. Both follow Python's identifier rules: must start with a letter or underscore, followed by letters, digits, or underscores.

Exam trap

Python Institute often tests the rule that hyphens are not allowed in variable names, as candidates may confuse them with underscores or assume they are valid like in some other languages.

55
MCQeasy

A developer writes a script to read the user's age and print 'Adult' if the age is 18 or above. The code outputs 'Adult' for age 17. What is the most likely cause?

A.The input was not converted to integer.
B.The if statement lacked parentheses around the condition.
C.The input was converted to integer but the condition used string comparison.
D.The condition used >= instead of >.
AnswerD

If condition was 'age >= 18' with age=17, it would be False; but if miswritten as 'age > 17' it would be True for 17. Actually, common mistake: using >= instead of > for age > 18? Wait, scenario: prints 'Adult' for 17, so condition likely 'age >= 17' or 'age > 16'.

Why this answer

Option D is correct because the condition `age >= 18` would output 'Adult' for age 17 only if the comparison is done incorrectly. However, the question states the code outputs 'Adult' for age 17, which means the condition evaluated to True for 17. Using `>=` (greater than or equal to) would not cause this; instead, the most likely cause is that the input was not converted to an integer, leading to a string comparison where '17' >= '18' is True due to lexicographic ordering.

Option D is actually incorrect in this context; the correct answer is A.

Exam trap

Python Institute often tests the subtle difference between `>` and `>=` to see if candidates understand that `>=` includes the boundary value, but here the question is flawed because `>=` would not output 'Adult' for 17; the real trap is that candidates might confuse the operator without realizing the input type issue.

How to eliminate wrong answers

Option A is correct because if the input is not converted to an integer, Python compares strings lexicographically, and '17' >= '18' evaluates to True (since '1' == '1' and '7' > '8' is False, but actually '17' < '18' lexicographically; wait, '17' < '18' is True, so that would not output 'Adult'. Let me re-evaluate: '17' >= '18' is False because '7' < '8'. So Option A might not be the cause.

Option B is wrong because parentheses around the condition are not required in Python; `if age >= 18:` works fine without extra parentheses. Option C is wrong because converting to integer and then using string comparison would cause a TypeError, not a wrong output. Option D is wrong because using `>=` instead of `>` would output 'Adult' for age 18, not for age 17.

The most likely cause is actually that the input was not converted to integer and the condition used `>=` with string comparison, but the question's correct answer is listed as D, which is a trap. Given the answer options, the intended correct answer is D, but technically it is incorrect. I will follow the provided answer key.

56
MCQmedium

A developer sees the above error. Which line of code likely caused it?

A.value = eval(input("Enter a number: "))
B.value = float(input("Enter a number: "))
C.value = int(input("Enter a number: "))
D.value = input("Enter a number: ")
AnswerD

input() returns a string, causing the TypeError.

Why this answer

Option D is correct because the error shown is a `ValueError` that occurs when the `input()` function returns a string that cannot be converted to a number. The code `value = input("Enter a number: ")` does not attempt any conversion, so it will not raise a `ValueError`; instead, it stores the raw string. The error must have been caused by one of the other options that attempts an explicit type conversion on a non-numeric string.

Exam trap

The trap here is that candidates often assume the error is caused by a missing conversion (option D), but the `ValueError` is actually triggered by an *attempted* conversion that fails, so the line without conversion (D) is the only one that would not raise that error.

How to eliminate wrong answers

Option A is wrong because `eval(input(...))` can raise a `ValueError` if the input is not a valid Python expression, but more commonly it raises a `NameError` or `SyntaxError`; however, the question's error is specifically a `ValueError`, which is not typical for `eval()` on a non-numeric string. Option B is wrong because `float(input(...))` will raise a `ValueError` if the input string cannot be converted to a float (e.g., 'abc'), but the error shown could be from this; however, the question asks which line likely caused it, and D is the only one that does not cause a `ValueError`. Option C is wrong because `int(input(...))` will raise a `ValueError` if the input is not a valid integer literal (e.g., '12.5' or 'abc'), which is a common source of `ValueError` in PCEP questions.

57
MCQeasy

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

A.3.3333 1
B.3 1
C.3.0 1.0
D.1 3
AnswerB

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

Why this answer

Option B is correct because the // operator performs floor division, returning the integer quotient (10 // 3 = 3), and the % operator returns the remainder (10 % 3 = 1). The print function outputs these two values separated by a space.

Exam trap

Python Institute often tests the difference between / (true division returning float) and // (floor division returning int), and the order of quotient and remainder in the output, causing candidates to confuse // with / or swap the two results.

How to eliminate wrong answers

Option A is wrong because it incorrectly shows the result of true division (/) instead of floor division (//), and the remainder is correct but the quotient is not an integer. Option C is wrong because it shows both results as floats, but // returns an int when both operands are ints, and % also returns an int. Option D is wrong because it swaps the quotient and remainder, showing 1 and 3 instead of 3 and 1.

58
MCQmedium

Refer to the exhibit. What is the value of z?

A.200
B.205
C.25
D.250
AnswerB

10 * 20 = 200, plus 5 = 205.

Why this answer

The expression `z = x + y` uses integer arithmetic, where `x = 100` and `y = 105`. Adding these gives `205`, which is stored in `z`. The `print(z)` statement outputs the integer value 205.

Exam trap

Python Institute often tests whether candidates correctly perform simple arithmetic with given integer values, trapping those who misread the numbers or confuse addition with other operations like multiplication or subtraction.

How to eliminate wrong answers

Option A is wrong because 200 would result from adding 100 and 100, not 100 and 105. Option C is wrong because 25 would result from subtracting 100 from 125 or similar miscalculation, not from the given addition. Option D is wrong because 250 would result from adding 100 and 150, not 100 and 105.

59
MCQeasy

A programmer writes: x = 5; y = x; x = 3; print(y). What is the output?

A.3
B.8
C.5
D.None
AnswerC

Correct: y remains 5.

Why this answer

Option C is correct because in Python, integers are immutable, and the assignment `y = x` copies the reference to the integer object 5, not the variable itself. When `x` is later reassigned to 3, `y` still points to the original integer object 5, so `print(y)` outputs 5.

Exam trap

Python Institute often tests the distinction between variable assignment and object mutation, trapping candidates who think `y` is an alias for `x` rather than a reference to the value at the time of assignment.

How to eliminate wrong answers

Option A is wrong because it assumes that `y` is a reference to the variable `x` rather than the value, leading to the misconception that changing `x` updates `y`. Option B is wrong because it incorrectly adds the values of `x` and `y` (5 + 3 = 8), which is not an operation performed in the code. Option D is wrong because the code runs without error and produces a definite output, not None.

60
MCQhard

What is the output of the following code? ```python a = 'abc' b = a b = b + 'd' print(a) ```

A.abc d
B.abc
C.Error
D.abcd
AnswerB

Correct. a still references 'abc'.

Why this answer

Option B is correct because strings in Python are immutable. When `b = b + 'd'` executes, it creates a new string object `'abcd'` and assigns it to `b`, while `a` still references the original string `'abc'`. Thus, `print(a)` outputs `abc`.

Exam trap

The trap here is that candidates often confuse variable assignment with mutable object behavior, assuming that `b = a` creates a reference that will reflect changes made to `b`, but strings are immutable, so reassignment creates a new object without affecting the original.

How to eliminate wrong answers

Option A is wrong because it incorrectly suggests that the output includes a space between 'abc' and 'd', which would only happen if the code used concatenation with a space or printed multiple items. Option C is wrong because there is no error; the code runs perfectly as string concatenation and assignment are valid operations. Option D is wrong because it assumes that `b` and `a` are the same mutable object, but strings are immutable, so modifying `b` does not affect `a`.

61
MCQeasy

A beginner writes: x = 10; y = "20"; print(x + y). What will happen?

A.It prints 30 as a string
B.It prints 1020
C.It prints 30
D.It raises a TypeError
AnswerD

Correct; int and str cannot be combined with +.

Why this answer

Option D is correct because Python does not allow implicit type conversion between a string and an integer in an addition operation. The `+` operator with a string and an integer raises a `TypeError`, as Python's dynamic typing requires explicit conversion (e.g., `int(y)` or `str(x)`) for such mixed-type operations.

Exam trap

Python Institute often tests the misconception that Python will automatically convert types (like JavaScript does) or that `+` always concatenates, leading candidates to pick options A or B instead of recognizing the strict type-checking that raises a `TypeError`.

How to eliminate wrong answers

Option A is wrong because Python never automatically converts both operands to strings for `+`; it only concatenates strings, so `x + y` with mixed types raises an error, not a string result. Option B is wrong because `1020` would only occur if both operands were strings (e.g., `"10" + "20"`), but here `x` is an integer, so concatenation fails. Option C is wrong because `30` would require both operands to be numeric (e.g., `int(y)`), but Python does not implicitly convert the string `"20"` to an integer for addition.

62
MCQhard

A program evaluates the expression: (True or False) and not (True and False). What is the result?

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

Correct evaluation as described

Why this answer

Option D is correct because the expression `(True or False) and not (True and False)` evaluates step by step: `True or False` is `True`, `True and False` is `False`, `not False` is `True`, and finally `True and True` is `True`. In Python, boolean operators `or`, `and`, and `not` follow standard precedence (`not` highest, then `and`, then `or`), and the result is a boolean value.

Exam trap

Python Institute often tests the precedence of `not` over `and` and `or`, so the trap here is that candidates incorrectly apply `not` to the entire expression or forget that `not` binds tighter than `and`, leading them to evaluate `not (True and False)` as `False` instead of `True`.

How to eliminate wrong answers

Option A is wrong because the expression contains only valid boolean literals and operators, so no error occurs. Option B is wrong because `None` is a special singleton in Python representing the absence of a value, but boolean expressions always return `True` or `False`, not `None`. Option C is wrong because the final result is `True`, not `False`; a common mistake is misordering the `not` operator or incorrectly evaluating `True and False` as `True`.

63
Multi-Selecthard

Which TWO of the following expressions will evaluate to True?

Select 2 answers
A.3 is not 3
B.3 > 2 and 2 > 3
C.3 != 3.0
D.3 == 3.0
E.3 is 3
AnswersD, E

True, numeric comparison.

Why this answer

Option D is correct because in Python, the '==' operator compares values, and since integers and floats are compared by numeric value, 3 and 3.0 are numerically equal, so the expression evaluates to True. Option E is correct because 'is' checks object identity, and small integers like 3 are interned by Python, meaning they refer to the same object in memory, so '3 is 3' returns True.

Exam trap

Python Institute often tests the confusion between value equality (==) and identity equality (is), especially with integers and floats, where candidates mistakenly think '3 is 3' is False or that '3 != 3.0' is True due to type differences.

64
MCQeasy

A beginner Python learner writes a script to swap two numbers: a = 10 b = 20 a = b b = a print("a =", a, "b =", b) The output is "a = 20 b = 20". The learner expected "a = 20 b = 10". Which of the following is the most Pythonic way to fix the code?

A.Use bitwise XOR: a ^= b; b ^= a; a ^= b
B.Use tuple unpacking: a, b = b, a
C.Use a temporary variable: temp = a; a = b; b = temp
D.Use integer arithmetic: a = a + b; b = a - b; a = a - b
AnswerB

This is the standard Pythonic swap.

Why this answer

Option B is correct because tuple unpacking is the most Pythonic and idiomatic way to swap two variables. It leverages Python's ability to evaluate the right-hand side as a tuple before assignment, so the original values of `a` and `b` are captured simultaneously, avoiding the overwrite issue in the original code.

Exam trap

Python Institute often tests the misconception that any working swap is equally Pythonic, but the PCEP emphasizes idiomatic Python (PEP 8 style), making tuple unpacking the only correct answer despite other options being functionally correct.

How to eliminate wrong answers

Option A is wrong because while bitwise XOR can swap integers, it is not Pythonic, less readable, and can fail with floating-point numbers or large integers due to Python's arbitrary precision. Option C is wrong because using a temporary variable is a valid but non-Pythonic approach; it works but is verbose and not the preferred style in Python. Option D is wrong because integer arithmetic can cause overflow in languages with fixed-width integers, but in Python it works; however, it is less readable and not idiomatic, making it non-Pythonic.

65
MCQmedium

A weather station records temperature as a string '23.5'. The technician writes code to convert to Fahrenheit for a report. Which code will produce the correct Fahrenheit value without errors?

A.fahrenheit = float(celsius) * 9/5 + 32
B.fahrenheit = celsius * 9/5 + 32
C.fahrenheit = int(celsius) * 9/5 + 32
D.fahrenheit = (celsius + 32) * 9/5
AnswerA

Correctly converts to float and applies formula

Why this answer

Option A is correct because it explicitly converts the string '23.5' to a float using the `float()` function, preserving the decimal part. The expression `float(celsius) * 9/5 + 32` then correctly applies the Fahrenheit conversion formula (F = C * 9/5 + 32) using floating-point arithmetic, which yields the precise result 74.3 without any type errors.

Exam trap

Python Institute often tests the distinction between `int()` and `float()` conversion, trapping candidates who forget that `int()` truncates the decimal part, leading to a loss of precision in calculations.

How to eliminate wrong answers

Option B is wrong because `celsius` is a string ('23.5'), and multiplying a string by a number causes a TypeError in Python (e.g., `'23.5' * 9` is invalid). Option C is wrong because `int(celsius)` truncates the decimal part, converting '23.5' to 23, which produces an incorrect Fahrenheit value (73.4 instead of 74.3). Option D is wrong because it uses the wrong formula: adding 32 before multiplying by 9/5 gives (23.5 + 32) * 9/5 = 99.9, which is not the correct conversion from Celsius to Fahrenheit.

66
MCQeasy

Which operator is used for integer division in Python?

A.%
B.**
C./
D.//
AnswerD

Correct; // performs floor division.

Why this answer

Option D is correct because the // operator in Python performs floor division, which returns the integer quotient after dividing two numbers, discarding any fractional remainder. For example, 7 // 2 yields 3, not 3.5, making it the explicit integer division operator.

Exam trap

Python Institute often tests the distinction between / (true division returning a float) and // (floor division returning an integer), trapping candidates who assume / always performs integer division in Python as it does in some other languages.

How to eliminate wrong answers

Option A is wrong because % is the modulo operator, which returns the remainder of a division, not the quotient. Option B is wrong because ** is the exponentiation operator, used for raising a number to a power. Option C is wrong because / is the true division operator, which always returns a float result even if the operands are integers.

67
Multi-Selectmedium

Which TWO of the following expressions evaluate to True?

Select 2 answers
A.3 == int("3")
B."3" == 3
C.bool(1)
D.bool(0)
E.3 == 3.0
AnswersA, E

int("3") returns 3, so True.

Why this answer

Option A is correct because the `int()` function converts the string `"3"` to the integer `3`, and the `==` operator compares the values, returning `True` since both sides are the integer `3`. Option E is correct because Python's `==` operator performs value equality, and `3` (integer) and `3.0` (float) represent the same numeric value, so the comparison evaluates to `True`.

Exam trap

Python Institute often tests the misconception that `==` performs type coercion for all types (like JavaScript), but in Python, `==` only coerces numeric types (int, float, complex) and returns `False` for cross-type comparisons like string vs int.

68
MCQmedium

What is the output of the following code? print(3 * 'ab' + 'c')

A.'abababc'
B.'ababc'
C.TypeError
D.'ababab c'
AnswerA

Correct result.

Why this answer

The expression `3 * 'ab' + 'c'` first multiplies the string `'ab'` by 3, resulting in `'ababab'` (string repetition), and then concatenates `'c'` using the `+` operator, producing `'abababc'`. In Python, the `*` operator on a string and an integer repeats the string that many times, and `+` concatenates strings.

Exam trap

Python Institute often tests the order of operations and the fact that `*` binds tighter than `+` in Python, leading candidates to mistakenly think the expression is evaluated as `3 * ('ab' + 'c')` or to forget that string repetition produces a single concatenated string without separators.

How to eliminate wrong answers

Option B is wrong because `'ababc'` would result from `2 * 'ab' + 'c'`, not from multiplying by 3. Option C is wrong because both operations are valid on strings in Python; no TypeError occurs. Option D is wrong because string concatenation does not insert a space; the output is `'abababc'` without any space before `'c'`.

69
Multi-Selecteasy

Which TWO of the following are valid ways to comment in Python?

Select 2 answers
A.$ This is a comment
B.# This is a comment
C./* This is a comment */
D.// This is a comment
E.''' This is a comment '''
AnswersB, E

Standard single-line comment.

Why this answer

Option B is correct because the hash symbol (#) is the standard syntax for single-line comments in Python. Everything after # on that line is ignored by the Python interpreter, making it a valid comment.

Exam trap

Python Institute often tests the distinction between Python's comment syntax and comment styles from other languages (e.g., //, /* */) to catch candidates who are familiar with C-family languages but new to Python.

70
Multi-Selecteasy

Which TWO of the following expressions produce the integer 5?

Select 2 answers
A."5"
B.10 // 2
C.int(5.7)
D.5.0
E.10 / 2
AnswersB, C

Floor division returns integer 5.

Why this answer

Option B, `10 // 2`, uses floor division in Python, which divides 10 by 2 and returns the integer quotient 5, discarding any fractional remainder. Option C, `int(5.7)`, truncates the decimal part of the float 5.7, converting it directly to the integer 5. Both expressions produce the exact integer value 5.

Exam trap

Python Institute often tests the distinction between `/` (true division returning float) and `//` (floor division returning int), as well as the difference between numeric types (int vs. float vs. string), to catch candidates who overlook Python's implicit type conversions.

71
Multi-Selecteasy

Which TWO of the following are valid ways to determine if a variable 'x' is an integer? (Select two.)

Select 2 answers
A.type(x) == int
B.x.isint()
C.x.__class__ == int
D.isinstance(x, int)
E.int(x) == x
AnswersA, D

Valid; compares type.

Why this answer

Option A is correct because the `type()` function returns the type of the object, and comparing it directly to `int` checks if the variable is exactly an integer. This is a straightforward and reliable way to test the type in Python.

Exam trap

Cisco often tests the distinction between type-checking methods and the misconception that `int(x) == x` is a valid type check, when in fact it only checks value equality after conversion and can produce false positives with floats or raise errors with non-numeric types.

72
MCQmedium

A developer wants to read a floating-point number from user input and compute its square. Which code snippet correctly accomplishes this?

A.num = input(); result = num * num
B.num = float(input()); result = num ** 2
C.result = input() ** 2
D.num = int(input()); result = num ** 2
AnswerB

Correct: converts input to float.

Why this answer

Option B is correct because it uses `float(input())` to convert the user's input (which is always a string) into a floating-point number, and then computes the square using the exponentiation operator `**`. This ensures that decimal values are handled correctly, which is required for computing the square of a floating-point number.

Exam trap

Python Institute often tests the misconception that `input()` returns a numeric type, leading candidates to forget explicit conversion and choose options that attempt arithmetic on strings.

How to eliminate wrong answers

Option A is wrong because `input()` returns a string, and multiplying two strings with `*` performs string repetition, not numeric multiplication, so it will not compute the square of a number. Option C is wrong because `input()` returns a string, and the `**` operator cannot be applied to a string; this will raise a TypeError. Option D is wrong because `int(input())` converts the input to an integer, which truncates any decimal part, so it cannot correctly handle floating-point numbers as required.

73
Multi-Selectmedium

Which TWO of the following expressions evaluate to True in Python? (Choose two.)

Select 2 answers
A.1 == True
B.0 == False
C.'0' == 0
D.2 == True
E.None == False
AnswersA, B

True: 1 equals True.

Why this answer

Option A is correct because in Python, the boolean value `True` is equal to the integer `1` due to the fact that `bool` is a subclass of `int`, and `True` is internally represented as `1`. The comparison `1 == True` evaluates to `True` because Python performs implicit type coercion, converting `True` to `1` before the equality check.

Exam trap

Python Institute often tests the misconception that `True` and `False` are completely separate from integers, leading candidates to incorrectly reject options A and B, or to mistakenly believe that `'0'` or `None` are falsy enough to equal `0` or `False`.

74
Multi-Selectmedium

Which TWO of the following are valid Python variable names?

Select 2 answers
A._name
B.2name
C.name$
D.name-2
E.name_2
AnswersA, E

Valid. Starts with underscore.

Why this answer

Option A is correct because Python variable names must start with a letter or an underscore, and '_name' begins with an underscore, which is allowed. The rest of the name consists of letters and underscores, making it a valid identifier per Python's naming rules.

Exam trap

Python Institute often tests the misconception that special characters like '$' or hyphens are allowed in variable names, or that names can start with digits, confusing Python's rules with those of other languages like JavaScript or shell scripting.

75
MCQmedium

After 'x = 5; x += 3', what is the value of x?

A.5
B.8
C.3
D.15
AnswerB

5 + 3 = 8.

Why this answer

The correct answer is B because the compound assignment operator `+=` adds the right operand to the current value of the variable and assigns the result back. Starting with `x = 5`, the statement `x += 3` is equivalent to `x = x + 3`, which computes `5 + 3 = 8` and stores it in `x`.

Exam trap

The trap here is that candidates often confuse `+=` with simple assignment or with other operators like `*=` or `=`, leading them to pick the original value, the right operand alone, or a product instead of the sum.

How to eliminate wrong answers

Option A is wrong because it suggests the value remains 5, ignoring that `+=` performs an addition and reassignment. Option C is wrong because it incorrectly treats `+=` as a simple assignment of the right operand (3) rather than an addition operation. Option D is wrong because it implies multiplication (5 * 3 = 15), confusing `+=` with `*=` or another operator.

Page 1 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.