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.
Start practicing
Data Types, Variables, Basic I/O and Operators — choose a session length
Free · No account required
Domain overview
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.
Exam objectives
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
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.
Click any question to see the full explanation and answer options, or start a focused practice session above.
A developer writes the following code: x = 5; y = 2; print(x // y). What is the output?
2A junior developer writes: x = 10; y = 3; print(x % y). What will be printed?
3A developer needs to convert a string '25' to an integer and then add 10. Which code correctly performs this?
4What is the correct way to read a floating-point number from user input and store it in a variable?
5A 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?
6Which of the following is a valid variable name in Python?
7A developer writes: print(10 * '5'). What is the output?
8What is the result of the expression: print(2 ** 3 ** 2) ?
9A beginner writes: x = '10'; y = 20; print(x + y). What happens?
10Which operator is used to check if two values are equal in Python?
11A developer writes: a = 3; b = 4; c = a + b / 2. What is the value of c?
12Which TWO of the following are valid ways to create a variable with the integer value 100?
13Which THREE of the following expressions evaluate to True?
14Which TWO of the following are valid Python data types?
15Which FOUR of the following are correct uses of the print() function?
16What is the data type of z after executing z = 10 / 2?
17You 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?
18A 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?
19A 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?
20A 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?
21Which TWO of the following are valid variable names in Python? (Choose two.)
22What is the output of the code in the exhibit?
23A 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?
24A 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?
25A programmer writes: x = 5; y = x; x = 3; print(y). What is the output?
26A developer wants to read a floating-point number from user input and compute its square. Which code snippet correctly accomplishes this?
27A script uses the // operator with negative numbers. For example, -7 // 2 returns -4. The developer expected -3. Which statement best explains this behavior?
28A 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?
29A programmer needs to swap the values of two variables a and b without using a temporary variable. Which approach works in Python?
30Which TWO of the following expressions evaluate to True in Python? (Choose two.)
31Which THREE of the following are built-in Python data types? (Choose three.)
32Order the steps to define and call a function in Python.
33Order the steps to write a for loop that iterates over a range of numbers.
34Order the steps to debug a Python script using print statements.
35Match each Python data structure to its characteristic.
36Match each Python control flow statement to its purpose.
37Which of the following is a valid Python variable name?
38A program uses 'x = 3.14' and 'y = int(x)'. What is the value of y?
39Given 'a = 10; b = 3; c = a // b; d = a % b', what is the value of c + d?
40What does 'print(2 ** 3)' output?
41After 'x = 5; x += 3', what is the value of x?
42What is the result of 'bool(0) and bool(1)'?
43Which function is used to read user input as a string?
44What is the output of 'print(3 * "ab")'?
45Given 's = "Hello"; t = s[0:3]; print(t)', what is the output?
46Which TWO of the following are valid Python variable names?
47Which THREE of the following are Python built-in data types?
48Refer to the exhibit. What is the cause of the error?
49Given x = 100 and y = 105, what is the value of z if z = x + y?
50Refer to the exhibit. The code used is: name = input('Enter name: '); print('Hello', name). What will be printed if the user enters 'Alice'?
51A developer writes the following code: result = (5 + 3) * 2 ** 3 // 4. What is the value of result?
52Which of the following variable names is valid in Python?
53An 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?
54A junior developer writes: print('Hello' + 5). This code raises an error. What is the best way to fix it?
55A 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?
56Which data type is the result of: value = 10 // 3?
57A program needs to check if a number is both positive and even. Which expression correctly implements this?
58Given the code: x = 10; y = 3.0; z = x / y; print(type(z)). What is the output?
59A 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?
60Which TWO of the following expressions evaluate to True?
61Which THREE of the following statements about Python operators are true?
62Refer to the exhibit. What is the output of the Python code?
63Refer to the exhibit. Which of the following shows the correct output?
64Refer to the exhibit. What is the printed value?
65A developer writes: x = 5; y = 2.0; z = x / y; print(type(z)). What is the output?
66A program contains this code: print(1 and 2 or 3). What is the output?
67A developer runs the following code: x = 0.1; y = 0.2; print(x + y == 0.3). What is the output and why?
68A developer wants to store a person's age. Which of these variable names is invalid?
69A developer writes: num = input('Enter a number: '); result = num * 2; print(result). If the user enters 5, what is the output?
70A developer needs to check if a variable x is between 10 and 20 (inclusive). Which expression is correct?
71What is the output of: print(10 // 3, 10 % 3)?
72A developer accidentally wrote: print('Hello' + 5). What happens?
73Which TWO of the following Python data types are mutable?
74Which THREE of the following are valid Python variable names?
75Which THREE of the following are Python data types?
76What is the output when the following code is executed? try: print(1/0) except ZeroDivisionError: print("Cannot divide by zero")
77What is the output of the following code? config = {} print('Not set' if config.get('timeout') is None else config.get('timeout'))
78What is the output from the interactive Python session?
79A 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?
80A program prompts a user for their age using input(). Which line of code correctly stores the age as an integer?
81Which of the following expressions evaluates to False?
82A developer writes: total = 2 ** 3 + 4. What is the value of total?
83A developer wrote: x = 10; y = 5; x += y * 2. What are the values of x and y after execution?
84What is the output of print(type(3 + 4.5))?
85A program checks divisibility. Which condition correctly determines if a number n is divisible by 7?
86Which TWO of the following expressions produce the integer 5?
87A Python program loads this JSON and accesses the first rule's action. Which expression gives the string "permit"?
88Based on the exhibit, which expression returns 2.5 in Python?
89Which operator performs integer (floor) division in Python?
90What is the output of the following code? print(3 * 'ab' + 'c')
91A program needs to read a user's age and print a message if they are 18 or older. Which code snippet correctly accomplishes this?
92What is the data type of the expression (3.14 > 2) and ('a' < 'b')?
93Given x = 5, which of the following assignments will cause a runtime error?
94A function sometimes returns None. Which expression correctly checks if the return value is not None?
95Which of the following expressions will evaluate to True?
96Which TWO of the following are Python membership operators?
97Which THREE of the following are immutable data types in Python?
98Which TWO of the following expressions will evaluate to True?
99Refer to the exhibit. What is the output?
100A 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?
101A developer needs to swap the values of two variables a and b in a single line of code. Which statement correctly accomplishes this?
102What is the output of the following code? ```python x = 10 y = 3 print(x // y * y + x % y) ```
103What is the output of the following code? ```python print('Hello', 'World', sep='-') ```
104Which data type is most appropriate to store a user's age in a Python program?
105What is the type of the result of the expression 5 + 3.0?
106Given the code: ```python name = input('Enter your name: ') print('Hello, ' + name) ``` If the user enters 'Alice', what is the output?
107What is the output of the following code? ```python a = 'abc' b = a b = b + 'd' print(a) ```
108What is the output of the code?
109Which TWO data types are immutable in Python?
110A 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?
111A programmer writes: x = 5; y = "10"; z = x + y. What will happen?
112Which of the following is an invalid variable name in Python?
113A 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?
114What is the result of bool(0) in Python?
115Evaluate the expression: not (True or False) and (False or True). What is the result?
116Which of the following variable names is NOT valid in Python?
117Which expression evaluates to False?
118A developer runs the command and sees the output. Which statement about the data type is correct?
119A 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.
120Which THREE of the following statements about Python operators are correct?
121A 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?
122A 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?
123A developer writes the following code: x = 5; y = x; x = 10. What are the values of x and y after execution?
124What is the output of the following code? print('Hello', 'World', sep='-', end='!\n')
125A program evaluates the expression: (True or False) and not (True and False). What is the result?
126What is the result of 17 % 5 in Python?
127A programmer writes: result = 'Py' * 2 + 'thon'. What is the value of result?
128A user enters '42' at an input prompt. After executing x = input(), what is the type of x?
129A 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?
130Which three of the following are Python arithmetic operators? (Choose three.)
131A beginner writes: x = 10; y = "20"; print(x + y). What will happen?
132A program calculates BMI. User inputs weight and height as strings. Which line correctly converts to float?
133After executing: a = 5; b = 2; c = a // b; d = a % b; e = a ** b. What is the value of (c + d) * 2 - e?
134Which of the following is NOT a valid variable name in Python?
135A developer needs to read an integer from user input and store it. Which code snippet accomplishes this?
136What is the output of the following code? print(type(3.0) == float)
137Which operator is used for integer division in Python?
138A program prints a greeting: name = input("Enter name: "); print("Hello, " + name + "!"). If user enters "Alice", what is output?
139Consider: x = True; y = False; z = x and not y or x. What is the value of z?
140Which THREE of the following expressions evaluate to the integer 1? (Select three.)
141Which TWO of the following expressions evaluate to 0? (Select two.)
142A 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?
143A 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?
144Which of the following expressions evaluate to True? (Choose three.)
145Given 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
146A 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?
147A 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?
148A 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?
149A 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?
150A 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?
151A Python script contains the following code: x = 0.1 + 0.2 y = 0.3 print(x == y) What is printed?
152A student writes the following code: name = "Alice" age = 25 print("Name: " + name + ", Age: " + age) What happens when the code runs?
153A Python script contains the following assignment: `value = 5` followed by `result = value * '2'`. What is the value of `result` after these statements execute?
154A Python script contains the following code: num = 7 result = num ** 2 print(result) What is the output?
155A 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?
156A 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?
157A Python programmer writes the following code: x = 5 y = 2 result = x / y print(type(result)) What is printed?
158A programmer writes the following code: `x = 7` then `y = 2` then `z = x / y`. What is the data type and value of `z`?
159A 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?
160A 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?
161A 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?
162Consider the following code: `x = 5` then `y = 2` then `result = x // y * y + x % y`. What is the value of `result`?
163A Python programmer is analyzing the results of several expressions. Which TWO of the following expressions evaluate to a float value? (Choose two.)
164A 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?
165A Python script contains: print(10 / 4) print(10 // 4) print(10 % 4) What output does this produce?
166A Python script contains the following code: price = 19.99 quantity = 3 total = price * quantity print(type(total)) What is displayed when this script runs?
167A 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.)
168A 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?
169A Python developer writes the following code to concatenate two strings: first = 'Hello' second = 'World' result = first + ' ' + second print(result) What is the output?
170A 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'>'?
171A 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?
172A 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?
173A script starts with: name = "Ada" age = 36 Which line correctly prints: Ada is 36 years old
174A developer is inspecting a variable and writes: value = 7.0 // 2. What is the value and type of the result assigned to 'value'?
175A developer writes a script to track inventory: apples = 15 oranges = 4 apples -= oranges oranges += apples print(apples, oranges) What is printed?
176A 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?
177A script runs: x = 5 y = x y += 3 print(x, y) What is printed?
178A 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?
179A 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.)
180A developer is reviewing operators in Python. Which TWO of the following statements about comparison and logical operators are correct? (Choose two.)
181A developer runs this code: a = 10 b = 3 a += b * 2 a //= b print(a) What is printed?
Deep-dive questions
The most-searched questions in this domain — detailed explanations, worked examples, full answer breakdowns.
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.
The Courseiva PCEP question bank contains 181 questions in the Data Types, Variables, Basic I/O and Operators domain, covering the 25% of the exam attributed to this domain in the official Python Institute blueprint. Click any question to see the full explanation and answer breakdown.
Start with a 10-question focused session to identify your baseline accuracy in this domain. Read every explanation — even for questions you answer correctly — to understand the reasoning. Once you score consistently above 80%, move to a 20–30 question session to confirm depth before moving to the next domain.
Yes — the session launcher on this page draws questions exclusively from the Data Types, Variables, Basic I/O and Operators domain. Choose 10, 20, 30, or 50 questions for a focused session, or click individual questions to review them one by one.
Save your results, see per-domain analytics, and get readiness scores — free, for every certification.
Sign Up FreeFree forever · Every certification included