PCEP Data Types, Variables, Basic I/O and Operators • Complete Question Bank
Complete PCEP Data Types, Variables, Basic I/O and Operators question bank — all 0 questions with answers and detailed explanations.
Refer to the exhibit. x = 7 y = 2 result = x / y print(type(result))
Refer to the exhibit.
name = input('Enter name: ')
age = input('Enter age: ')
print(name + ' is ' + age + ' years old.')Refer to the exhibit. x = 10 y = 3.0 z = x * y print(z)
You are a junior developer at a logistics company. Your team is building a system to calculate shipping costs based on package weight. The system reads weight from user input. A colleague wrote the following code: weight = input('Enter weight in kg: '); cost = weight * 2.5; print('Shipping cost:', cost). However, when testing with weight 10, the output is 'Shipping cost: 10101010101010101010' (the string '10' repeated 2.5 times? Actually, 2.5 is float, but string multiplied by float causes TypeError? Wait, string * float raises TypeError. But the symptom described suggests the code runs but produces unexpected output. Let me re-read: The output shows '10101010101010101010' which is the string '10' repeated 10 times? That would happen if weight is string and multiplied by int 10. But the code multiplies by 2.5. Actually, string * float raises TypeError, so the code would crash. The symptom must be plausible. Let me adjust: The code actually has weight = input(...), then cost = weight * 2.5, but if weight is '10', then '10' * 2.5 raises TypeError. So the symptom cannot be that output. I need to fix the stem to make sense. Instead, let's say the code is: weight = input('Enter weight: '); cost = float(weight) * 2.5; print('Cost:', cost). But then no issue. I'll create a scenario where the developer forgot to convert input to float, and then tries to multiply string by float, which causes TypeError. The correct action is to convert input to float. I'll adjust the stem accordingly. Let me rewrite the stem properly.
Stem: You are a developer at a shipping company. The system calculates shipping cost as weight (kg) times rate 2.5. A colleague wrote: weight = input('Enter weight: '); cost = weight * 2.5; print('Cost:', cost). When testing with weight 10, the program crashes with TypeError. Which action should you take to fix the code?
Refer to the exhibit. >>> x = 10 >>> y = 3 >>> z = x // y >>> print(z)
Refer to the exhibit.
name = input('Enter name: ')
age = input('Enter age: ')
print(name + ' is ' + age + ' years old.')
If the user enters 'Alice' and '25', what is the output?Refer to the exhibit. x = 10.5 y = 3 result = x // y print(result) What is the output of this code?
Drag steps to the numbered slots on the right, or tap a step then tap a slot.
Drag steps to the numbered slots on the right, or tap a step then tap a slot.
Drag steps to the numbered slots on the right, or tap a step then tap a slot.
Drag a concept onto its matching description — or click a concept then click the description.
Equality comparison operator
Inequality comparison operator
Floor division operator
Modulus (remainder) operator
Exponentiation operator
Drag a concept onto its matching description — or click a concept then click the description.
Ordered, immutable sequence of items
Unordered collection of unique items
Mapping of key-value pairs
Ordered, mutable sequence of items
Immutable sequence of characters
Drag a concept onto its matching description — or click a concept then click the description.
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
Traceback (most recent call last):
File "script.py", line 3, in <module>
result = "5" + 10
TypeError: can only concatenate str (not "int") to str>>> x = 10 >>> y = 20 >>> z = x * y + 5 >>> print(z) 205
Enter name: Bob Hello Bob
Refer to the exhibit. ``` >>> print(3 * 'abc') ```
Refer to the exhibit. ```python a = 10 b = 3 print(a / b) print(a // b) print(a % b) ```
Refer to the exhibit. ```python x = 5 y = 2 z = x ** y + x % y * 2 print(z) ```
Refer to the exhibit.
def divide(a, b):
try:
result = a / b
print('Result:', result)
except ZeroDivisionError:
print('Cannot divide by zero')
except TypeError:
print('Unsupported operand')
divide(10, 0)Refer to the exhibit. >>> x = 10 >>> y = 3 >>> print(x // y, x % y)
Refer to the exhibit.
Error output:
Traceback (most recent call last):
File "script.py", line 3, in <module>
result = value + 10
TypeError: can only concatenate str (not "int") to strRefer to the exhibit.
JSON policy file:
{
"name": "access-policy",
"rules": [
{"action": "permit", "src": "10.0.0.0/24", "dst": "0.0.0.0/0", "protocol": "tcp"},
{"action": "deny", "src": "0.0.0.0/0", "dst": "10.0.0.0/24", "protocol": "tcp"}
]
}Refer to the exhibit. Command output: >>> 5 // 2 2 >>> 5 % 2 1 >>> 5 / 2 2.5
What is the output of the following code?
print(3 * 'ab' + 'c')
x = input("Enter x: ")
y = input("Enter y: ")
print(x + y)num = "10.5" result = int(num) print(result)
a = 10 // 3 b = 10 % 3 print(a, b)
A student writes the following code to calculate the average of two numbers: ```python num1 = input("Enter first number: ") num2 = input("Enter second number: ") avg = (num1 + num2) / 2
print("Average:", avg)``` When executed, the code raises a TypeError. What is the most likely cause?
What is the output of the following code? ```python x = 10 y = 3
print(x // y * y + x % y)
```
What is the output of the following code? ```python
print('Hello', 'World', sep='-')```
Given the code: ```python name = input('Enter your name: ')
print('Hello, ' + name)``` If the user enters 'Alice', what is the output?
What is the output of the following code? ```python a = 'abc' b = a b = b + 'd'
print(a)
```
Refer to the exhibit. x = 7 y = 2 result = x / y print(type(result))
Refer to the exhibit.
Code:
age = input('Enter your age: ')
print(age * 2)
Input:
Enter your age: 25Refer to the exhibit.
Error message:
Traceback (most recent call last):
File "script.py", line 3, in <module>
result = "The answer is " + 42
TypeError: can only concatenate str (not "int") to strRefer to the exhibit. Output of command: python3 -c "print(type(3.14))" <class 'float'>
Refer to the exhibit.
JSON policy:
{
"policy": "allow",
"ports": [80, 443]
}What is the output of the following code?
print('Hello', 'World', sep='-', end='!\n')>>> x = 10 >>> y = "20" >>> print(x + y) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for +: 'int' and 'str'
A company needs to calculate the average of three test scores entered by a user. The scores are integers. The programmer writes the following code:
s1 = input("Enter score 1: ") s2 = input("Enter score 2: ") s3 = input("Enter score 3: ") avg = (s1 + s2 + s3) / 3
print("Average:", avg)When run, the output is incorrect. What is the most likely cause?
Given the following code, which of the following statements are true after execution? (Choose three.)
x = 10 y = 3.0 z = x / y w = x // y
A junior developer is writing a script to calculate the total cost of items in a shopping cart. The script uses variables item_price (float) and quantity (int). The code is:
item_price = 2.5 quantity = 3 total = item_price * quantity
print("Total: " + total)When run, this code raises a TypeError. The developer is confused because the multiplication seems correct. What is the most likely issue and the correct fix?
A data analyst needs to read two integers from the user and compute their average as a float. The current code:
a = int(input()) b = int(input()) avg = a + b / 2
print(avg)
The output is always incorrect when a=5 and b=7 (expected 6.0, actual 8.5). The analyst cannot identify the bug. What is the root cause and correct fix?
A 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 student is learning Python and writes a program to compute the area of a rectangle. The code:
length = input("Enter length: ") width = input("Enter width: ") area = length * width
print("Area:", area)When the user enters 5 and 3, the program crashes with a TypeError: can't multiply sequence by non-int of type 'str'. The student is puzzled because they thought input returns numbers. What is the correct explanation and fix?
A developer is building a simple calculator that accepts two numbers and an operator string. The code:
x = float(input("First: ")) y = float(input("Second: ")) op = input("Operator (+, -, *, /): ")
if op == "+":
result = x + y elif op == "-": result = x - y elif op == "*": result = x * y elif op == "/": result = x / y
print("Result:", result)When the user enters 10, 3, and "/", the output is "Result: 3.3333333333333335". The developer wants to display only two decimal places. Which code change will achieve this without introducing errors?
A 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 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 developer is working on a project that requires handling large numbers. They write:
x = 10000000000 y = 3.0 z = x / y
print(int(z))
The output is 3333333333. However, the developer expected 3333333333 (same). But they suspect that integer division might be better. They try:
x = 10000000000 y = 3 z = x // y
print(z)
Output: 3333333333. Both give same. Now they test with negative numbers:
x = -10 y = 3 z1 = x / y z2 = x // y
print(z1, z2)
The output is -3.3333333333333335 and -4. The developer is confused why z2 is -4 instead of -3. Which of the following explains the behavior?
A data scientist needs to read a list of floats from a file, one per line, and compute the sum. The current code:
total = 0.0
with open("data.txt") as f:
for line in f:total = total + line
print(total)
When run, a TypeError occurs: unsupported operand type(s) for +: 'float' and 'str'. The scientist knows that line is a string. Which fix will correctly sum the numbers?
A student tries to write a program that prints the square of a number. The code:
num = 5
print("The square is " + num ** 2)When run, a TypeError occurs. Which of the following fixes the error and produces exactly the output 'The square is 25'?