Practice PCEP Data Types, Variables, Basic I/O and Operators questions with full explanations on every answer.
Start practicing
Data Types, Variables, Basic I/O and Operators — choose a session length
Free · No account required
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 THREE of the following are correct uses of the print() function?
16What is the output of the code?
17A user enters 'Alice' for name and '30' for age. What is the output?
18What is the data type of z?
19You 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?
20You 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?
21A 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 17. What is the most likely cause?
22A 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?
23A 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?
24Which TWO of the following are valid variable names in Python? (Choose two.)
25What is the output of the code in the exhibit?
26You 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?
27A 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?
28A 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?
29A 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?
30A programmer writes: x = 5; y = x; x = 3; print(y). What is the output?
31A developer wants to read a floating-point number from user input and compute its square. Which code snippet correctly accomplishes this?
32A script uses the // operator with negative numbers. For example, -7 // 2 returns -4. The developer expected -3. Which statement best explains this behavior?
33A 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?
34A programmer needs to swap the values of two variables a and b without using a temporary variable. Which approach works in Python?
35Which TWO of the following are valid variable names in Python? (Choose two.)
36Which TWO of the following expressions evaluate to True in Python? (Choose two.)
37Which THREE of the following are built-in Python data types? (Choose three.)
38A developer runs the script and enters 'Alice' and '25'. What does it print?
39Given the exhibit, what does the code print?
40A 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?
41A 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?
42Order the steps to define and call a function in Python.
43Order the steps to write a for loop that iterates over a range of numbers.
44Order the steps to debug a Python script using print statements.
45Match each Python operator to its description.
46Match each Python data structure to its characteristic.
47Match each Python control flow statement to its purpose.
48Which of the following is a valid Python variable name?
49A program uses 'x = 3.14' and 'y = int(x)'. What is the value of y?
50Given 'a = 10; b = 3; c = a // b; d = a % b', what is the value of c + d?
51What does 'print(2 ** 3)' output?
52After 'x = 5; x += 3', what is the value of x?
53What is the result of 'bool(0) and bool(1)'?
54Which function is used to read user input as a string?
55What is the output of 'print(3 * "ab")'?
56Given 's = "Hello"; t = s[0:3]; print(t)', what is the output?
57Which TWO of the following are valid Python variable names?
58Which THREE of the following are Python built-in data types?
59Which TWO operators in Python yield an integer result when applied to two integers?
60Refer to the exhibit. What is the cause of the error?
61Refer to the exhibit. What is the value of z?
62Refer to the exhibit. The code used is: name = input('Enter name: '); print('Hello', name). What will be printed if the user enters 'Alice'?
63A developer writes the following code: result = (5 + 3) * 2 ** 3 // 4. What is the value of result?
64Which of the following variable names is valid in Python?
65An 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?
66A junior developer writes: print('Hello' + 5). This code raises an error. What is the best way to fix it?
67A 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?
68Which data type is the result of: value = 10 // 3?
69A program needs to check if a number is both positive and even. Which expression correctly implements this?
70Given the code: x = 10; y = 3.0; z = x / y; print(type(z)). What is the output?
71A 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?
72Which TWO of the following are valid ways to comment in Python?
73Which TWO of the following expressions evaluate to True?
74Which THREE of the following statements about Python operators are true?
75Refer to the exhibit. What is the output of the Python code?
76Refer to the exhibit. Which of the following shows the correct output?
77Refer to the exhibit. What is the printed value?
78A 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?
79A developer writes: x = 5; y = 2.0; z = x / y; print(type(z)). What is the output?
80A program contains this code: print(1 and 2 or 3). What is the output?
81A developer runs the following code: x = 0.1; y = 0.2; print(x + y == 0.3). What is the output and why?
82A developer wants to store a person's age. Which of these variable names is invalid?
83A developer writes: num = input('Enter a number: '); result = num * 2; print(result). If the user enters 5, what is the output?
84A developer needs to check if a variable x is between 10 and 20 (inclusive). Which expression is correct?
85What is the output of: print(10 // 3, 10 % 3)?
86A developer accidentally wrote: print('Hello' + 5). What happens?
87Which TWO of the following Python data types are mutable?
88Which THREE of the following are valid Python variable names?
89Which THREE of the following are Python data types?
90What is the output when the code is executed?
91What is the output?
92What is the output from the interactive Python session?
93A 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?
94A program prompts a user for their age using input(). Which line of code correctly stores the age as an integer?
95Which of the following expressions evaluates to False?
96A developer writes: total = 2 ** 3 + 4. What is the value of total?
97What is the output of print(10 // 3, 10 % 3)?
98Which of the following is a valid Python variable name?
99A developer wrote: x = 10; y = 5; x += y * 2. What are the values of x and y after execution?
100What is the output of print(type(3 + 4.5))?
101A program checks divisibility. Which condition correctly determines if a number n is divisible by 7?
102Which TWO of the following expressions produce the integer 5?
103Which TWO of the following are valid Python variable names?
104Which THREE of the following are arithmetic operators in Python?
105A developer sees the above error. Which line of code likely caused it?
106A Python program loads this JSON and accesses the first rule's action. Which expression gives the string "permit"?
107Based on the exhibit, which expression returns 2.5 in Python?
108Which of the following is a valid Python variable name?
109Which operator performs integer (floor) division in Python?
110Which of the following is a valid floating-point literal in Python?
111What is the output of the following code? print(3 * 'ab' + 'c')
112A program needs to read a user's age and print a message if they are 18 or older. Which code snippet correctly accomplishes this?
113What is the data type of the expression (3.14 > 2) and ('a' < 'b')?
114Given x = 5, which of the following assignments will cause a runtime error?
115A function sometimes returns None. Which expression correctly checks if the return value is not None?
116Which of the following expressions will evaluate to True?
117Which TWO of the following are Python membership operators?
118Which THREE of the following are immutable data types in Python?
119Which TWO of the following expressions will evaluate to True?
120Refer to the exhibit. If the user enters 5 and 3, what is the output?
121Refer to the exhibit. What will happen when this code is executed?
122Refer to the exhibit. What is the output?
123A 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?
124A developer needs to swap the values of two variables a and b in a single line of code. Which statement correctly accomplishes this?
125What is the output of the following code? ```python x = 10 y = 3 print(x // y * y + x % y) ```
126What is the output of the following code? ```python print('Hello', 'World', sep='-') ```
127Which data type is most appropriate to store a user's age in a Python program?
128A function is designed to return False if a number is not divisible by 2. Which of the following return statements correctly implements this logic?
129What is the type of the result of the expression 5 + 3.0?
130Given the code: ```python name = input('Enter your name: ') print('Hello, ' + name) ``` If the user enters 'Alice', what is the output?
131What is the output of the following code? ```python a = 'abc' b = a b = b + 'd' print(a) ```
132What is the output of the code?
133What is the output?
134What is the output when the user enters 25?
135Which TWO of the following are valid Python variable names?
136Which THREE of the following expressions evaluate to True?
137Which TWO data types are immutable in Python?
138A 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?
139A programmer writes: x = 5; y = "10"; z = x + y. What will happen?
140A 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?
141Which of the following is an invalid variable name in Python?
142A 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?
143What is the result of bool(0) in Python?
144Evaluate the expression: not (True or False) and (False or True). What is the result?
145Which of the following variable names is NOT valid in Python?
146Which expression evaluates to False?
147What is the most appropriate fix for the error shown in the exhibit?
148A developer runs the command and sees the output. Which statement about the data type is correct?
149A 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.
150Which TWO of the following are valid Python data types?
151Which TWO of the following expressions evaluate to True?
152Which THREE of the following statements about Python operators are correct?
153A 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?
154A 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?
155A developer writes the following code: x = 5; y = x; x = 10. What are the values of x and y after execution?
156What is the output of the following code? print('Hello', 'World', sep='-', end='!\n')
157A program evaluates the expression: (True or False) and not (True and False). What is the result?
158What is the result of 17 % 5 in Python?
159A programmer writes: result = 'Py' * 2 + 'thon'. What is the value of result?
160A user enters '42' at an input prompt. After executing x = input(), what is the type of x?
161Refer to the exhibit. A beginner Python programmer executes the code and gets an error. What is the most likely cause?
162A 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?
163Which two of the following are valid Python variable names? (Choose two.)
164Which three of the following are Python arithmetic operators? (Choose three.)
165Which two of the following expressions return the value 5? (Choose two.)
166A 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?
167A 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?
168A beginner writes: x = 10; y = "20"; print(x + y). What will happen?
169A program calculates BMI. User inputs weight and height as strings. Which line correctly converts to float?
170After executing: a = 5; b = 2; c = a // b; d = a % b; e = a ** b. What is the value of (c + d) * 2 - e?
171Which of the following is NOT a valid variable name in Python?
172A developer needs to read an integer from user input and store it. Which code snippet accomplishes this?
173What is the output of the following code? print(type(3.0) == float)
174Which operator is used for integer division in Python?
175A program prints a greeting: name = input("Enter name: "); print("Hello, " + name + "!"). If user enters "Alice", what is output?
176Consider: x = True; y = False; z = x and not y or x. What is the value of z?
177Which TWO of the following are valid ways to determine if a variable 'x' is an integer? (Select two.)
178Which THREE of the following expressions evaluate to the integer 1? (Select three.)
179Which TWO of the following expressions evaluate to 0? (Select two.)
180A 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?
181A 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?
182A 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?
183A 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?
184Which of the following are valid Python variable names? (Choose two.)
185Which of the following expressions evaluate to True? (Choose three.)
186Given 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
187A 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?
188A 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?
189A 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?
190A 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?
191A 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?
192A 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?
193A 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?
194A 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?
195A 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?
196A 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'?
The Data Types, Variables, Basic I/O and Operators domain covers the key concepts tested in this area of the PCEP exam blueprint published by Python Institute. Courseiva provides free domain-focused practice, mock exams, missed-question review, and readiness tracking across all PCEP domains — no account required.
The Courseiva PCEP question bank contains 196 questions in the Data Types, Variables, Basic I/O and Operators domain. 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