Courseiva

PCEP · domain

Data Types, Variables, Basic I/O and Operators

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.

181 questions56 easy79 medium46 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

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.

Question index

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

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

1

A Python programmer is analyzing the results of several expressions. Which TWO of the following expressions evaluate to a float value? (Choose two.)

Hard
2

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

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

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
6

Match each Python control flow statement to its purpose.

Medium
7

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

Hard
8

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

Easy
9

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

Medium
10

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

Easy
11

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
12

Which TWO of the following are valid Python data types?

Easy
13

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

Easy
14

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

Hard
15

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

Medium
16

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

Medium
17

A Python programmer wants to determine whether the variable n is an even number greater than zero. Which expression correctly evaluates to True only when n is a positive even integer?

Medium
18

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

Hard
19

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

Easy
20

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

Medium
21

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

Easy
22

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
23

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

Medium
24

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

Hard
25

Which TWO of the following are valid Python variable names?

Easy
26

A Python script contains the following assignment: `value = 5` followed by `result = value * '2'`. What is the value of `result` after these statements execute?

Easy
27

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
28

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

Hard
29

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

Medium
30

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
31

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

Medium
32

Which operator performs integer (floor) division in Python?

Easy
33

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

Easy
34

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
35

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

Hard
36

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

Hard
37

A cashier script stores a product's unit price as a string read from a barcode label: price = '4.50'. The developer must compute the total for 3 units and print a numeric result. Which code produces the value 13.5?

Easy
38

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

Medium
39

A developer runs this code: a = 10 b = 3 a += b * 2 a //= b print(a) What is printed?

Medium
40

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
41

Which THREE of the following expressions evaluate to True?

Hard
42

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
43

Which THREE of the following are valid Python variable names?

Hard
44

Refer to the exhibit. What is the printed value?

Hard
45

A developer is reviewing operators in Python. Which TWO of the following statements about comparison and logical operators are correct? (Choose two.)

Hard
46

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

Medium
47

A developer writes a script to track inventory: apples = 15 oranges = 4 apples -= oranges oranges += apples print(apples, oranges) What is printed?

Hard
48

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

Hard
49

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
50

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
51

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

Medium
52

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
53

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

Easy
54

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

Medium
55

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

Easy
56

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

Hard
57

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

Easy
58

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

Hard
59

Which TWO of the following expressions will evaluate to True?

Hard
60

A login script checks whether a username entered by the user is exactly 'admin' and the account is not locked. The variable locked is a boolean. Which expression evaluates to True only when the username is 'admin' and locked is False?

Medium
61

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
62

Which operator is used for integer division in Python?

Easy
63

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

Medium
64

Which TWO of the following expressions produce the integer 5?

Easy
65

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

Medium
66

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

Medium
67

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

Medium
68

A Python script contains the following code: num = 7 result = num ** 2 print(result) What is the output?

Easy
69

Which of the following expressions evaluates to False?

Easy
70

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

Hard
71

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

Easy
72

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
73

A developer writes the following code to calculate a total price with tax: price = 19.99 tax_rate = 0.08 total = price + price * tax_rate print(round(total, 2)) What is printed?

Medium
74

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

Medium
75

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

Easy
76

Which expression evaluates to False?

Hard
77

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
78

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

Medium
79

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

Medium
80

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

Medium
81

Which TWO of the following are Python membership operators?

Easy
82

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

Easy
83

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

Easy
84

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

Medium
85

Which TWO of the following expressions evaluate to True?

Medium
86

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

Hard
87

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

Medium
88

A developer writes a script that records a product price. The line is: price = 19.99 Later, the script runs print(type(price)). What is displayed?

Medium
89

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

Medium
90

A Python script stores a product identifier as id = '0042'. A developer needs to print the numeric value 42 followed by the type of the converted value in one line. Which code produces the output '42 <class 'int'>'?

Easy
91

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

Easy
92

What is the output of the code?

Medium
93

A Python developer is reviewing a script that contains several variable declarations. They want to identify which assignments use valid variable names according to Python's naming rules. Which TWO of the following variable names are valid? (Choose two.)

Medium
94

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

Hard
95

Which of the following is a valid Python variable name?

Easy
96

A cashier script stores a discount rate and a price, then computes the final amount. The developer writes: rate = 0.15 price = 200 final = price - price * rate print(final) What is printed?

Medium
97

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
98

Which TWO of the following Python data types are mutable?

Medium
99

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

Easy
100

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
101

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
102

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

Hard
103

Which TWO data types are immutable in Python?

Easy
104

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

Medium
105

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

Hard
106

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
107

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

Easy
108

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

Hard
109

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

Easy
110

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

Hard
111

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
112

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

Medium
113

A script starts with: name = "Ada" age = 36 Which line correctly prints: Ada is 36 years old

Medium
114

A Python script contains: print(10 / 4) print(10 // 4) print(10 % 4) What output does this produce?

Easy
115

A programmer writes the following code: `x = 7` then `y = 2` then `z = x / y`. What is the data type and value of `z`?

Medium
116

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

Medium
117

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

Easy
118

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

Hard
119

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

Hard
120

A cashier script stores a price as a string and needs to apply a 10 percent discount. The code is: price = "19.99" discount = 0.10 final = price * (1 - discount) print(final) What happens when this code runs?

Medium
121

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
122

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
123

A student is analyzing Python code and wants to understand the result of the expression `2 ** 3 ** 2` in Python 3. What value does this expression produce?

Easy
124

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

Medium
125

A student writes the following code: name = "Alice" age = 25 print("Name: " + name + ", Age: " + age) What happens when the code runs?

Easy
126

A Python script contains the following code: price = 19.99 quantity = 3 total = price * quantity print(type(total)) What is displayed when this script runs?

Easy
127

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

Hard
128

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
129

Which THREE of the following are Python data types?

Easy
130

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

Medium
131

Which of the following expressions will evaluate to True?

Hard
132

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
133

Which of the following variable names is valid in Python?

Easy
134

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

Easy
135

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
136

A student writes a program to classify a number: num = 7 result = num > 5 and num < 10 or num == 0 print(result) What is printed, and why?

Medium
137

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

Medium
138

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

Medium
139

What is the output from the interactive Python session?

Easy
140

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

Medium
141

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
142

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

Hard
143

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

Medium
144

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

Easy
145

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

Hard
146

A programmer writes the following code to calculate the average of two numbers: a = 5 b = 2 avg = a / b print(avg) What is the output?

Medium
147

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
148

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

Medium
149

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

Hard
150

A Python developer writes the following code to concatenate two strings: first = 'Hello' second = 'World' result = first + ' ' + second print(result) What is the output?

Medium
151

What is the result of 17 % 5 in Python?

Easy
152

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
153

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

Easy
154

Consider the following code: `x = 5` then `y = 2` then `result = x // y * y + x % y`. What is the value of `result`?

Hard
155

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
156

A script runs: x = 5 y = x y += 3 print(x, y) What is printed?

Hard
157

A Python programmer writes the following code: x = 5 y = 2 result = x / y print(type(result)) What is printed?

Hard
158

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

Medium
159

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

Easy
160

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

Medium
161

A developer needs to swap the values of two variables a and b without using a temporary variable. Which single line of code correctly performs the swap?

Medium
162

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

Easy
163

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

Medium
164

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

Medium
165

A developer is inspecting a variable and writes: value = 7.0 // 2. What is the value and type of the result assigned to 'value'?

Medium
166

A Python script performs the following operations: s = "Hello" n = 5 result1 = s * 2 result2 = s + str(n) Which TWO statements about the values of result1 and result2 are true? (Choose two.)

Medium
167

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
168

A quiz program stores a user's score as score = 7 and the number of questions as total = 2. The developer writes percentage = score / total * 100. What value is displayed?

Medium
169

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
170

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
171

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

Hard
172

Match each Python data structure to its characteristic.

Medium
173

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

Medium
174

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

Medium
175

Refer to the exhibit. What is the output?

Easy
176

What is the output of the code in the exhibit?

Medium
177

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

Medium
178

A Python script contains the following code: x = 0.1 + 0.2 y = 0.3 print(x == y) What is printed?

Medium
179

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

Medium
180

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

Easy
181

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?
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 many questions are in this domain?
This page lists all 181 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