Courseiva

PCEP · topic practice

Data Types, Variables, Basic I/O and Operators practice questions

This PCEP domain covers Python's core data types (int, float, str, bool), variable assignment and naming, the print() and input() functions, and operators including arithmetic, comparison, logical, and assignment. Questions present short code snippets and ask you to predict output, identify a value's type, or judge a statement about the result.

Courseiva uses original exam-style practice questions designed for learning and revision. The goal is to understand the concepts, recognise exam patterns, and improve through explanations — not memorise copied exam dumps.

Editorial oversight:Johnson Ajibi· MSc IT Security, IEEE Senior Member
20 questionsDomain: Data Types, Variables, Basic I/O and Operators

What the exam tests

What to know about Data Types, Variables, Basic I/O and Operators

You must read short Python snippets and correctly state the printed output or the type of a value. The single most important thing to get right is Python 3 division: / always produces a float, while // floors the result, so predict types before values.

Predicting output of print() calls using arithmetic operators like **, /, //, and %

Determining the type returned by expressions, e.g. type() of true division results

Recognizing int, float, str, and bool literals and how variables store them

Evaluating operator precedence and mixed-type expressions such as int combined with float

Watch out for

Common Data Types, Variables, Basic I/O and Operators exam traps

  • ▸Assuming / returns an int: in Python 3 true division always yields a float, even for evenly divisible operands like 10 / 5.
  • ▸Confusing // floor division with / division, or expecting // to round toward zero rather than toward negative infinity for negatives.
  • ▸Forgetting that input() always returns a string, so numeric input must be converted with int() or float() before arithmetic.

Practice set

Data Types, Variables, Basic I/O and Operators questions

20 questions · select your answer, then reveal the explanation

What is the output of the code?

Exhibit

Refer to the exhibit.

x = 7
y = 2
result = x / y
print(type(result))

A user enters 'Alice' for name and '30' for age. What is the output?

Exhibit

Refer to the exhibit.

name = input('Enter name: ')
age = input('Enter age: ')
print(name + ' is ' + age + ' years old.')

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?

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 program calculates the total price including tax: total = price * 1.08. The variable price is assigned as price = 100.0. After execution, total is 108.0. The developer then changes price to 100. What will total be?

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

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

Exhibit

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?

Given the exhibit, what does the code print?

Exhibit

Refer to the exhibit.

x = 10.5
y = 3
result = x // y
print(result)

What is the output of this code?
Question 9mediummultiple choice
Study the full Python automation breakdown →

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

Match each Python operator to its description.

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

Concepts
Matches

Equality comparison operator

Inequality comparison operator

Floor division operator

Modulus (remainder) operator

Exponentiation operator

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

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

A developer writes code to compute the average of two numbers entered by the user: x = input('Enter first number: '); y = input('Enter second number: '); avg = (x + y) / 2. The program produces an error. What is the best practice to fix the code?

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

Question 16mediummultiple choice
Study the full Python automation breakdown →

Which of the following is a valid Python variable name?

Which TWO of the following are valid Python variable names?

Which THREE of the following are arithmetic operators in Python?

A developer encounters a TypeError. Which line of code likely caused it?

Exhibit

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 str

Which of the following is a valid Python variable name?

Free account

Track your progress over time

Create a free account to save your results and see which topics improve across sessions.

Focused Data Types, Variables, Basic I/O and Operators sessions

Start a Data Types, Variables, Basic I/O and Operators only practice session

Every question in these sessions is drawn from the Data Types, Variables, Basic I/O and Operators domain — nothing else.

Related practice questions

Related PCEP topic practice pages

Move into related areas when this topic feels solid.

Frequently asked questions

What does the PCEP exam test about Data Types, Variables, Basic I/O and Operators?
You must read short Python snippets and correctly state the printed output or the type of a value. The single most important thing to get right is Python 3 division: / always produces a float, while // floors the result, so predict types before values.
How should I use these practice questions?
Select your answer before revealing the explanation. Then read why each option is right or wrong — this active recall approach builds retention far faster than re-reading notes.
Can I practise just Data Types, Variables, Basic I/O and Operators questions in a focused session?
Yes — the session launcher on this page draws every question from the Data Types, Variables, Basic I/O and Operators domain. Use a 10-question session first to gauge your baseline, then move to 20 or 30 once the weak spots are clear.
Where can I practise other PCEP topics?
Use the topic links above to move to related areas, or go back to the PCEP question bank to see all topics.
Are these real exam questions or dumps?
These are original practice questions written to test the same concepts the PCEP exam covers. They are not copied from any real exam or dump site.