Courseiva

PCEP · domain

Data Types, Variables, Basic I/O and Operators

Practise Certified Entry-Level Python Programmer PCEP Data Types, Variables, Basic I/O and Operators practice questions — original exam-style scenarios with answer choices, explanations, and analysis of common mistakes.

190 questions59 easy75 medium56 hard

Focused practice

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

Scored sessions drawing only from this domain — pick a length below.

Start 20-question practice test →

What this domain covers

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

Data Types, Variables, Basic I/O and Operators questions test whether you can apply the concept in context, not just recognise a definition.

How the topic appears in realistic exam-style scenarios.

Which detail in the question changes the correct answer.

How to eliminate plausible but wrong options.

How to connect the question back to the wider exam objective.

Watch out for

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

  • Answering from memory before reading the full scenario.
  • Missing a constraint such as cost, availability, security, scope or command context.
  • Choosing a broad answer when the question asks for the most specific fix.
  • Ignoring why the wrong options are tempting.

Question index

All Data Types, Variables, Basic I/O and Operators questions (190)

Click any question to see the full explanation, or start a practice session above.

1

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

Hard
2

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

Hard
3

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

Hard
4

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

Easy
5

Which of the following is a valid Python variable name?

Easy
6

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?

Medium
7

Match each Python control flow statement to its purpose.

Medium
8

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

Hard
9

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

Easy
10

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

Medium
11

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

Easy
12

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?

Hard
13

Which TWO of the following are valid Python data types?

Easy
14

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

Easy
15

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

Hard
16

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

Medium
17

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?

Hard
18

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

Medium
19

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

Easy
20

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

Easy
21

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

Hard
22

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

Easy
23

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?

Hard
24

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

Medium
25

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

Easy
26

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?

Hard
27

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

Medium
28

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

Hard
29

Which TWO of the following are valid Python variable names?

Easy
30

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.

Medium
31

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

Hard
32

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

Medium
33

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?

Hard
34

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

Medium
35

Which operator performs integer (floor) division in Python?

Easy
36

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

Easy
37

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?

Easy
38

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

Hard
39

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

Hard
40

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

Medium
41

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

Hard
42

Which TWO of the following are valid Python data types?

Easy
43

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?

Medium
44

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?

Hard
45

Which THREE of the following expressions evaluate to True?

Hard
46

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

Hard
47

Which THREE of the following are valid Python variable names?

Hard
48

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

Medium
49

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

Hard
50

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?

Medium
51

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

Medium
52

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

Medium
53

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 9. What is the most likely cause?

Easy
54

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

Medium
55

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

Easy
56

Given x = 100 and y = 105, what is the value of z if z = x + y?

Medium
57

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

Easy
58

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

Hard
59

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

Easy
60

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

Hard
61

Which TWO of the following expressions will evaluate to True?

Hard
62

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?

Easy
63

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?

Medium
64

Which operator is used for integer division in Python?

Easy
65

Which THREE of the following expressions evaluate to True?

Medium
66

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

Medium
67

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

Easy
68

Which TWO of the following expressions produce the integer 5?

Easy
69

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

Easy
70

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

Medium
71

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

Medium
72

Which TWO of the following are valid Python variable names?

Medium
73

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

Medium
74

Which of the following expressions evaluates to False?

Easy
75

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

Hard
76

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

Hard
77

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

Easy
78

What is the output of the code?

Medium
79

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

Easy
80

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

Medium
81

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

Easy
82

Which expression evaluates to False?

Hard
83

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?

Medium
84

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

Medium
85

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

Medium
86

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

Medium
87

Which TWO of the following are Python membership operators?

Easy
88

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

Easy
89

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

Easy
90

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?

Hard
91

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

Medium
92

What is the output when the user enters 25?

Easy
93

Which TWO of the following expressions evaluate to True?

Medium
94

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

Hard
95

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

Medium
96

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

Medium
97

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

Easy
98

What is the output of the code?

Medium
99

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

Hard
100

Which of the following is a valid Python variable name?

Easy
101

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?

Easy
102

Which TWO of the following Python data types are mutable?

Medium
103

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

Easy
104

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?

Easy
105

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

Medium
106

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

Easy
107

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

Hard
108

Which TWO data types are immutable in Python?

Easy
109

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

Medium
110

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

Hard
111

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

Hard
112

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?

Easy
113

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

Easy
114

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

Hard
115

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

Easy
116

What is the output of the following code? config = {} print('Not set' if config.get('timeout') is None else config.get('timeout'))

Hard
117

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

Hard
118

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

Medium
119

Which THREE of the following expressions evaluate to True?

Hard
120

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?

Hard
121

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

Medium
122

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

Easy
123

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

Hard
124

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

Hard
125

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

Hard
126

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

Hard
127

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'?

Easy
128

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

Hard
129

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

Medium
130

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

Medium
131

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

Hard
132

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

Easy
133

Which THREE of the following are Python data types?

Easy
134

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

Medium
135

Which of the following expressions will evaluate to True?

Hard
136

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?

Medium
137

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

Easy
138

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

Medium
139

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

Medium
140

Which of the following variable names is valid in Python?

Easy
141

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

Easy
142

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

Medium
143

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

Medium
144

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

Medium
145

What is the output from the interactive Python session?

Easy
146

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

Medium
147

A developer writes the following code: a = 3; b = 2; c = a / b; d = a // b; e = a % b. What are the values of c, d, e?

Medium
148

Consider: x = True; y = False; z = x and not y or x. What is the value of z?

Hard
149

Match each Python operator to its description.

Medium
150

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?

Hard
151

What is the output of 'print(3 * "ab")'?

Medium
152

Which function is used to read user input as a string?

Easy
153

What is the result of 'bool(0) and bool(1)'?

Hard
154

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?

Medium
155

Which TWO of the following are valid Python variable names?

Medium
156

A program uses 'x = 3.14' and 'y = int(x)'. What is the value of y?

Medium
157

Given the code: x = 10; y = 3.0; z = x / y; print(type(z)). What is the output?

Hard
158

What is the output?

Hard
159

What is the most appropriate fix for the error shown in the exhibit?

Hard
160

What is the result of 17 % 5 in Python?

Easy
161

A developer wants to output a variable price with two decimal places using formatting. Which line of code will produce 'Price: $12.50' for price = 12.5?

Medium
162

Which THREE of the following are arithmetic operators in Python?

Hard
163

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

Hard
164

What does 'print(2 ** 3)' output?

Easy
165

A developer wants to assign the value 3.14 to a variable and later change it to the integer 3. Which of the following is true?

Medium
166

Which of the following expressions evaluate to True? (Choose three.)

Medium
167

What is the type of the result of the expression 5 + 3.0?

Easy
168

Given the code: ```python name = input('Enter your name: ') print('Hello, ' + name) ``` If the user enters 'Alice', what is the output?

Medium
169

What is the data type of z after executing z = 10 / 2?

Easy
170

Which FOUR of the following are correct uses of the print() function?

Medium
171

Order the steps to write a for loop that iterates over a range of numbers.

Medium
172

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

Medium
173

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?

Easy
174

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?

Medium
175

After executing: a = 5; b = 2; c = a // b; d = a % b; e = a ** b. What is the value of (c + d) * 2 - e?

Hard
176

A developer writes a program to calculate the average of three numbers: a=10; b=20; c=30; avg = a + b + c / 3; print(avg). What is the output?

Easy
177

A Python program loads this JSON and accesses the first rule's action. Which expression gives the string "permit"?

Hard
178

Match each Python data structure to its characteristic.

Medium
179

What is the data type of the expression (3.14 > 2) and ('a' < 'b')?

Medium
180

A junior developer writes: print('Hello' + 5). This code raises an error. What is the best way to fix it?

Medium
181

Refer to the exhibit. What is the output?

Easy
182

A company runs a script that processes user input temperatures. The script expects integers but sometimes users enter floats. The current code is: temp = int(input("Enter temperature: ")). When a user enters "36.5", the script crashes with a ValueError. The developer needs to modify the script to handle both integer and float inputs gracefully, converting the input to an integer (by truncation) for processing. Which of the following is the best course of action?

Hard
183

What is the output of the code in the exhibit?

Medium
184

Which of the following is a valid Python variable name?

Medium
185

A company needs to process user input that must be a whole number between 1 and 100. Which code snippet correctly validates and converts the input?

Medium
186

What is the output when the following code is executed? try: print(1/0) except ZeroDivisionError: print("Cannot divide by zero")

Medium
187

A programmer needs to swap the values of two variables a and b without using a temporary variable. Which approach works in Python?

Medium
188

A developer is writing a program to calculate the average of three test scores. The current code reads scores as integers: a=int(input()); b=int(input()); c=int(input()); avg = (a+b+c)/3; print(avg). For scores 7, 8, and 9, the output is 8.0, but the requirement is to print the integer average (8), rounded to the nearest whole number. Which modification should the developer make to meet the requirement?

Medium
189

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

Easy
190

What is the output of the following code? print('Hello', 'World', sep='-', end='!\n')

Medium

Frequently asked questions

What does the Data Types, Variables, Basic I/O and Operators domain cover on the PCEP exam?
Data Types, Variables, Basic I/O and Operators questions test whether you can apply the concept in context, not just recognise a definition.
How many questions are in this domain?
This page lists all 190 Data Types, Variables, Basic I/O and Operators questions in the PCEP question bank. The actual exam draws from this domain proportionally to its weighting in the official exam blueprint.
What is the best way to practise this domain?
Start with a short focused session (10 questions) to identify gaps, then work through explanations. Repeat with a longer session once the weak areas feel solid.
Can I practise only Data Types, Variables, Basic I/O and Operators questions?
Yes — the session launcher on this page filters questions to this domain only. Choose any session length for inline explanations and scoring.
python-pcep PYTHON-PCEP data types variables Practice Questions