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.
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.
A Python programmer is analyzing the results of several expressions. Which TWO of the following expressions evaluate to a float value? (Choose two.)
Hard2What is the output of the following code? print(type(3.0) == float)
Hard3A function sometimes returns None. Which expression correctly checks if the return value is not None?
Hard4A developer writes the following code: result = (5 + 3) * 2 ** 3 // 4. What is the value of result?
Easy5A 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?
Medium6Match each Python control flow statement to its purpose.
Medium7Which THREE of the following statements about Python operators are true?
Hard8A beginner writes: x = '10'; y = 20; print(x + y). What happens?
Easy9A developer writes: num = input('Enter a number: '); result = num * 2; print(result). If the user enters 5, what is the output?
Medium10Which data type is the result of: value = 10 // 3?
Easy11A 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?
Hard12Which TWO of the following are valid Python data types?
Easy13A developer writes the following code: x = 5; y = 2; print(x // y). What is the output?
Easy14Which THREE of the following statements about Python operators are correct?
Hard15A developer writes: total = 2 ** 3 + 4. What is the value of total?
Medium16Which THREE of the following expressions evaluate to the integer 1? (Select three.)
Medium17A 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?
Medium18Given x = 5, which of the following assignments will cause a runtime error?
Hard19Refer to the exhibit. What is the cause of the error?
Easy20A program prints a greeting: name = input("Enter name: "); print("Hello, " + name + "!"). If user enters "Alice", what is output?
Medium21What is the output of the following code? ```python print('Hello', 'World', sep='-') ```
Easy22A 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?
Hard23Evaluate the expression: not (True or False) and (False or True). What is the result?
Medium24A developer wrote: x = 10; y = 5; x += y * 2. What are the values of x and y after execution?
Hard25Which TWO of the following are valid Python variable names?
Easy26A Python script contains the following assignment: `value = 5` followed by `result = value * '2'`. What is the value of `result` after these statements execute?
Easy27A 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.
Medium28A developer needs to check if a variable x is between 10 and 20 (inclusive). Which expression is correct?
Hard29Which THREE of the following are immutable data types in Python?
Medium30A 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?
Hard31Which operator is used to check if two values are equal in Python?
Medium32Which operator performs integer (floor) division in Python?
Easy33Based on the exhibit, which expression returns 2.5 in Python?
Easy34A 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?
Easy35A program checks divisibility. Which condition correctly determines if a number n is divisible by 7?
Hard36A developer runs the following code: x = 0.1; y = 0.2; print(x + y == 0.3). What is the output and why?
Hard37A 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?
Easy38A developer accidentally wrote: print('Hello' + 5). What happens?
Medium39A developer runs this code: a = 10 b = 3 a += b * 2 a //= b print(a) What is printed?
Medium40A script uses the // operator with negative numbers. For example, -7 // 2 returns -4. The developer expected -3. Which statement best explains this behavior?
Hard41Which THREE of the following expressions evaluate to True?
Hard42Refer to the exhibit. The code used is: name = input('Enter name: '); print('Hello', name). What will be printed if the user enters 'Alice'?
Hard43Which THREE of the following are valid Python variable names?
Hard44Refer to the exhibit. What is the printed value?
Hard45A developer is reviewing operators in Python. Which TWO of the following statements about comparison and logical operators are correct? (Choose two.)
Hard46Which THREE of the following are Python built-in data types?
Medium47A developer writes a script to track inventory: apples = 15 oranges = 4 apples -= oranges oranges += apples print(apples, oranges) What is printed?
Hard48What is the output of the following code? ```python x = 10 y = 3 print(x // y * y + x % y) ```
Hard49A 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?
Medium50A developer needs to swap the values of two variables a and b in a single line of code. Which statement correctly accomplishes this?
Medium51Which TWO of the following are valid variable names in Python? (Choose two.)
Medium52A 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?
Easy53What is the output of: print(10 // 3, 10 % 3)?
Easy54Given x = 100 and y = 105, what is the value of z if z = x + y?
Medium55A programmer writes: x = 5; y = x; x = 3; print(y). What is the output?
Easy56What is the output of the following code? ```python a = 'abc' b = a b = b + 'd' print(a) ```
Hard57A beginner writes: x = 10; y = "20"; print(x + y). What will happen?
Easy58A program evaluates the expression: (True or False) and not (True and False). What is the result?
Hard59Which TWO of the following expressions will evaluate to True?
Hard60A 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?
Medium61A 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?
Medium62Which operator is used for integer division in Python?
Easy63What is the output of the following code? print(3 * 'ab' + 'c')
Medium64Which TWO of the following expressions produce the integer 5?
Easy65A developer wants to read a floating-point number from user input and compute its square. Which code snippet correctly accomplishes this?
Medium66Which TWO of the following expressions evaluate to True in Python? (Choose two.)
Medium67After 'x = 5; x += 3', what is the value of x?
Medium68A Python script contains the following code: num = 7 result = num ** 2 print(result) What is the output?
Easy69Which of the following expressions evaluates to False?
Easy70What is the output of print(type(3 + 4.5))?
Hard71A user enters '42' at an input prompt. After executing x = input(), what is the type of x?
Easy72A 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?
Easy73A 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?
Medium74A program needs to check if a number is both positive and even. Which expression correctly implements this?
Medium75What is the result of bool(0) in Python?
Easy76Which expression evaluates to False?
Hard77A 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?
Medium78A programmer writes: result = 'Py' * 2 + 'thon'. What is the value of result?
Medium79Which of the following variable names is NOT valid in Python?
Medium80A developer runs the command and sees the output. Which statement about the data type is correct?
Medium81Which TWO of the following are Python membership operators?
Easy82Which of the following is a valid variable name in Python?
Easy83What is the correct way to read a floating-point number from user input and store it in a variable?
Easy84Order the steps to define and call a function in Python.
Medium85Which TWO of the following expressions evaluate to True?
Medium86What is the result of the expression: print(2 ** 3 ** 2) ?
Hard87A program calculates BMI. User inputs weight and height as strings. Which line correctly converts to float?
Medium88A 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?
Medium89Which three of the following are Python arithmetic operators? (Choose three.)
Medium90A 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'>'?
Easy91A programmer writes: x = 5; y = "10"; z = x + y. What will happen?
Easy92What is the output of the code?
Medium93A 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.)
Medium94Given 'a = 10; b = 3; c = a // b; d = a % b', what is the value of c + d?
Hard95Which of the following is a valid Python variable name?
Easy96A 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?
Medium97A 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?
Easy98Which TWO of the following Python data types are mutable?
Medium99A developer wants to store a person's age. Which of these variable names is invalid?
Easy100A 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?
Easy101You 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?
Medium102Which of the following is an invalid variable name in Python?
Hard103Which TWO data types are immutable in Python?
Easy104A developer writes: print(10 * '5'). What is the output?
Medium105Which THREE of the following are built-in Python data types? (Choose three.)
Hard106A 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?
Easy107A developer writes the following code: x = 5; y = x; x = 10. What are the values of x and y after execution?
Easy108Which TWO of the following expressions evaluate to 0? (Select two.)
Hard109A program prompts a user for their age using input(). Which line of code correctly stores the age as an integer?
Easy110What is the output of the following code? config = {} print('Not set' if config.get('timeout') is None else config.get('timeout'))
Hard111A 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?
Hard112A developer needs to read an integer from user input and store it. Which code snippet accomplishes this?
Medium113A script starts with: name = "Ada" age = 36 Which line correctly prints: Ada is 36 years old
Medium114A Python script contains: print(10 / 4) print(10 // 4) print(10 % 4) What output does this produce?
Easy115A programmer writes the following code: `x = 7` then `y = 2` then `z = x / y`. What is the data type and value of `z`?
Medium116A program contains this code: print(1 and 2 or 3). What is the output?
Medium117Refer to the exhibit. What is the output of the Python code?
Easy118A developer writes: a = 3; b = 4; c = a + b / 2. What is the value of c?
Hard119A developer needs to convert a string '25' to an integer and then add 10. Which code correctly performs this?
Hard120A 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?
Medium121Given 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
Hard122A program needs to read a user's age and print a message if they are 18 or older. Which code snippet correctly accomplishes this?
Medium123A 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?
Easy124A junior developer writes: x = 10; y = 3; print(x % y). What will be printed?
Medium125A student writes the following code: name = "Alice" age = 25 print("Name: " + name + ", Age: " + age) What happens when the code runs?
Easy126A Python script contains the following code: price = 19.99 quantity = 3 total = price * quantity print(type(total)) What is displayed when this script runs?
Easy127Given 's = "Hello"; t = s[0:3]; print(t)', what is the output?
Hard128A 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?
Easy129Which THREE of the following are Python data types?
Easy130Which data type is most appropriate to store a user's age in a Python program?
Medium131Which of the following expressions will evaluate to True?
Hard132A 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?
Easy133Which of the following variable names is valid in Python?
Easy134A developer writes: x = 5; y = 2.0; z = x / y; print(type(z)). What is the output?
Easy135An 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?
Medium136A 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?
Medium137Refer to the exhibit. Which of the following shows the correct output?
Medium138Which TWO of the following are valid ways to create a variable with the integer value 100?
Medium139What is the output from the interactive Python session?
Easy140Order the steps to debug a Python script using print statements.
Medium141A 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?
Medium142Consider: x = True; y = False; z = x and not y or x. What is the value of z?
Hard143What is the output of 'print(3 * "ab")'?
Medium144Which function is used to read user input as a string?
Easy145What is the result of 'bool(0) and bool(1)'?
Hard146A 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?
Medium147A 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?
Medium148A program uses 'x = 3.14' and 'y = int(x)'. What is the value of y?
Medium149Given the code: x = 10; y = 3.0; z = x / y; print(type(z)). What is the output?
Hard150A Python developer writes the following code to concatenate two strings: first = 'Hello' second = 'World' result = first + ' ' + second print(result) What is the output?
Medium151What is the result of 17 % 5 in Python?
Easy152A 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?
Medium153What does 'print(2 ** 3)' output?
Easy154Consider the following code: `x = 5` then `y = 2` then `result = x // y * y + x % y`. What is the value of `result`?
Hard155A 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?
Medium156A script runs: x = 5 y = x y += 3 print(x, y) What is printed?
Hard157A Python programmer writes the following code: x = 5 y = 2 result = x / y print(type(result)) What is printed?
Hard158Which of the following expressions evaluate to True? (Choose three.)
Medium159What is the type of the result of the expression 5 + 3.0?
Easy160Given the code: ```python name = input('Enter your name: ') print('Hello, ' + name) ``` If the user enters 'Alice', what is the output?
Medium161A 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?
Medium162What is the data type of z after executing z = 10 / 2?
Easy163Which FOUR of the following are correct uses of the print() function?
Medium164Order the steps to write a for loop that iterates over a range of numbers.
Medium165A developer is inspecting a variable and writes: value = 7.0 // 2. What is the value and type of the result assigned to 'value'?
Medium166A 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.)
Medium167A 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?
Medium168A 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?
Medium169After executing: a = 5; b = 2; c = a // b; d = a % b; e = a ** b. What is the value of (c + d) * 2 - e?
Hard170A 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?
Easy171A Python program loads this JSON and accesses the first rule's action. Which expression gives the string "permit"?
Hard172Match each Python data structure to its characteristic.
Medium173What is the data type of the expression (3.14 > 2) and ('a' < 'b')?
Medium174A junior developer writes: print('Hello' + 5). This code raises an error. What is the best way to fix it?
Medium175Refer to the exhibit. What is the output?
Easy176What is the output of the code in the exhibit?
Medium177What is the output when the following code is executed? try: print(1/0) except ZeroDivisionError: print("Cannot divide by zero")
Medium178A Python script contains the following code: x = 0.1 + 0.2 y = 0.3 print(x == y) What is printed?
Medium179A programmer needs to swap the values of two variables a and b without using a temporary variable. Which approach works in Python?
Medium180Which of the following is NOT a valid variable name in Python?
Easy181What is the output of the following code? print('Hello', 'World', sep='-', end='!\n')
MediumOther domains
All PCEP exam domains
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.