PCEP · domain
Data Types, Variables, Basic I/O and Operators
Practise Certified Entry-Level Python Programmer PCEP Data Types, Variables, Basic I/O and Operators practice questions — original exam-style scenarios with answer choices, explanations, and analysis of common mistakes.
Focused practice
Practice Data Types, Variables, Basic I/O and Operators questions
Scored sessions drawing only from this domain — pick a length below.
Start 20-question practice test →What this domain covers
What to know about Data Types, Variables, Basic I/O and Operators
Data Types, Variables, Basic I/O and Operators questions test whether you can apply the concept in context, not just recognise a definition.
How the topic appears in realistic exam-style scenarios.
Which detail in the question changes the correct answer.
How to eliminate plausible but wrong options.
How to connect the question back to the wider exam objective.
Watch out for
Common Data Types, Variables, Basic I/O and Operators exam traps
- ▸Answering from memory before reading the full scenario.
- ▸Missing a constraint such as cost, availability, security, scope or command context.
- ▸Choosing a broad answer when the question asks for the most specific fix.
- ▸Ignoring why the wrong options are tempting.
Question index
All Data Types, Variables, Basic I/O and Operators questions (190)
Click any question to see the full explanation, or start a practice session above.
What is the output of the following code? print(type(3.0) == float)
Hard2Which two of the following expressions return the value 5? (Choose two.)
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?
Easy5Which of the following is a valid Python variable name?
Easy6A 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?
Medium7Match each Python control flow statement to its purpose.
Medium8Which THREE of the following statements about Python operators are true?
Hard9A beginner writes: x = '10'; y = 20; print(x + y). What happens?
Easy10A developer writes: num = input('Enter a number: '); result = num * 2; print(result). If the user enters 5, what is the output?
Medium11Which data type is the result of: value = 10 // 3?
Easy12A 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?
Hard13Which TWO of the following are valid Python data types?
Easy14A developer writes the following code: x = 5; y = 2; print(x // y). What is the output?
Easy15Which THREE of the following statements about Python operators are correct?
Hard16A developer writes: total = 2 ** 3 + 4. What is the value of total?
Medium17A 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?
Hard18Which THREE of the following expressions evaluate to the integer 1? (Select three.)
Medium19Which of the following is a valid floating-point literal in Python?
Easy20Which TWO of the following are valid variable names in Python? (Choose two.)
Easy21Given x = 5, which of the following assignments will cause a runtime error?
Hard22Refer to the exhibit. What is the cause of the error?
Easy23You 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?
Hard24A program prints a greeting: name = input("Enter name: "); print("Hello, " + name + "!"). If user enters "Alice", what is output?
Medium25What is the output of the following code? ```python print('Hello', 'World', sep='-') ```
Easy26A 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?
Hard27Evaluate the expression: not (True or False) and (False or True). What is the result?
Medium28A developer wrote: x = 10; y = 5; x += y * 2. What are the values of x and y after execution?
Hard29Which TWO of the following are valid Python variable names?
Easy30A 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.
Medium31A developer needs to check if a variable x is between 10 and 20 (inclusive). Which expression is correct?
Hard32Which THREE of the following are immutable data types in Python?
Medium33A 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?
Hard34Which operator is used to check if two values are equal in Python?
Medium35Which operator performs integer (floor) division in Python?
Easy36Based on the exhibit, which expression returns 2.5 in Python?
Easy37A 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?
Easy38A program checks divisibility. Which condition correctly determines if a number n is divisible by 7?
Hard39A developer runs the following code: x = 0.1; y = 0.2; print(x + y == 0.3). What is the output and why?
Hard40A developer accidentally wrote: print('Hello' + 5). What happens?
Medium41A script uses the // operator with negative numbers. For example, -7 // 2 returns -4. The developer expected -3. Which statement best explains this behavior?
Hard42Which TWO of the following are valid Python data types?
Easy43A 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?
Medium44A 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?
Hard45Which THREE of the following expressions evaluate to True?
Hard46Refer to the exhibit. The code used is: name = input('Enter name: '); print('Hello', name). What will be printed if the user enters 'Alice'?
Hard47Which THREE of the following are valid Python variable names?
Hard48Which THREE of the following are Python built-in data types?
Medium49What is the output of the following code? ```python x = 10 y = 3 print(x // y * y + x % y) ```
Hard50A 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?
Medium51A developer needs to swap the values of two variables a and b in a single line of code. Which statement correctly accomplishes this?
Medium52Which TWO of the following are valid variable names in Python? (Choose two.)
Medium53A 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?
Easy54A developer encounters a TypeError. Which line of code likely caused it?
Medium55What is the output of: print(10 // 3, 10 % 3)?
Easy56Given x = 100 and y = 105, what is the value of z if z = x + y?
Medium57A programmer writes: x = 5; y = x; x = 3; print(y). What is the output?
Easy58What is the output of the following code? ```python a = 'abc' b = a b = b + 'd' print(a) ```
Hard59A beginner writes: x = 10; y = "20"; print(x + y). What will happen?
Easy60A program evaluates the expression: (True or False) and not (True and False). What is the result?
Hard61Which TWO of the following expressions will evaluate to True?
Hard62A 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?
Easy63A 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?
Medium64Which operator is used for integer division in Python?
Easy65Which THREE of the following expressions evaluate to True?
Medium66What is the output of the following code? print(3 * 'ab' + 'c')
Medium67Which TWO of the following are valid ways to comment in Python?
Easy68Which TWO of the following expressions produce the integer 5?
Easy69Which TWO of the following are valid ways to determine if a variable 'x' is an integer? (Select two.)
Easy70A developer wants to read a floating-point number from user input and compute its square. Which code snippet correctly accomplishes this?
Medium71Which TWO of the following expressions evaluate to True in Python? (Choose two.)
Medium72Which TWO of the following are valid Python variable names?
Medium73After 'x = 5; x += 3', what is the value of x?
Medium74Which of the following expressions evaluates to False?
Easy75Which TWO operators in Python yield an integer result when applied to two integers?
Hard76What is the output of print(type(3 + 4.5))?
Hard77A user enters '42' at an input prompt. After executing x = input(), what is the type of x?
Easy78What is the output of the code?
Medium79A 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?
Easy80A program needs to check if a number is both positive and even. Which expression correctly implements this?
Medium81What is the result of bool(0) in Python?
Easy82Which expression evaluates to False?
Hard83A 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?
Medium84A programmer writes: result = 'Py' * 2 + 'thon'. What is the value of result?
Medium85Which of the following variable names is NOT valid in Python?
Medium86A developer runs the command and sees the output. Which statement about the data type is correct?
Medium87Which TWO of the following are Python membership operators?
Easy88Which of the following is a valid variable name in Python?
Easy89What is the correct way to read a floating-point number from user input and store it in a variable?
Easy90A 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?
Hard91Order the steps to define and call a function in Python.
Medium92What is the output when the user enters 25?
Easy93Which TWO of the following expressions evaluate to True?
Medium94What is the result of the expression: print(2 ** 3 ** 2) ?
Hard95A program calculates BMI. User inputs weight and height as strings. Which line correctly converts to float?
Medium96Which three of the following are Python arithmetic operators? (Choose three.)
Medium97A programmer writes: x = 5; y = "10"; z = x + y. What will happen?
Easy98What is the output of the code?
Medium99Given 'a = 10; b = 3; c = a // b; d = a % b', what is the value of c + d?
Hard100Which of the following is a valid Python variable name?
Easy101A 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?
Easy102Which TWO of the following Python data types are mutable?
Medium103A developer wants to store a person's age. Which of these variable names is invalid?
Easy104A 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?
Easy105You 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?
Medium106Which of the following are valid Python variable names? (Choose two.)
Easy107Which of the following is an invalid variable name in Python?
Hard108Which TWO data types are immutable in Python?
Easy109A developer writes: print(10 * '5'). What is the output?
Medium110Which THREE of the following are built-in Python data types? (Choose three.)
Hard111Refer to the exhibit. What will happen when this code is executed?
Hard112A 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?
Easy113A developer writes the following code: x = 5; y = x; x = 10. What are the values of x and y after execution?
Easy114Which TWO of the following expressions evaluate to 0? (Select two.)
Hard115A program prompts a user for their age using input(). Which line of code correctly stores the age as an integer?
Easy116What is the output of the following code? config = {} print('Not set' if config.get('timeout') is None else config.get('timeout'))
Hard117A 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?
Hard118A developer needs to read an integer from user input and store it. Which code snippet accomplishes this?
Medium119Which THREE of the following expressions evaluate to True?
Hard120A 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?
Hard121A program contains this code: print(1 and 2 or 3). What is the output?
Medium122Refer to the exhibit. What is the output of the Python code?
Easy123Refer to the exhibit. A beginner Python programmer executes the code and gets an error. What is the most likely cause?
Hard124A function is designed to return False if a number is not divisible by 2. Which of the following return statements correctly implements this logic?
Hard125A developer writes: a = 3; b = 4; c = a + b / 2. What is the value of c?
Hard126A developer needs to convert a string '25' to an integer and then add 10. Which code correctly performs this?
Hard127A 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'?
Easy128Given 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
Hard129A program needs to read a user's age and print a message if they are 18 or older. Which code snippet correctly accomplishes this?
Medium130A junior developer writes: x = 10; y = 3; print(x % y). What will be printed?
Medium131Given 's = "Hello"; t = s[0:3]; print(t)', what is the output?
Hard132A 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?
Easy133Which THREE of the following are Python data types?
Easy134Which data type is most appropriate to store a user's age in a Python program?
Medium135Which of the following expressions will evaluate to True?
Hard136A 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?
Medium137A 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?
Easy138Refer to the exhibit. If the user enters 5 and 3, what is the output?
Medium139What is the output of print(10 // 3, 10 % 3)?
Medium140Which of the following variable names is valid in Python?
Easy141A developer writes: x = 5; y = 2.0; z = x / y; print(type(z)). What is the output?
Easy142An 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?
Medium143Refer to the exhibit. Which of the following shows the correct output?
Medium144Which TWO of the following are valid ways to create a variable with the integer value 100?
Medium145What is the output from the interactive Python session?
Easy146Order the steps to debug a Python script using print statements.
Medium147A 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?
Medium148Consider: x = True; y = False; z = x and not y or x. What is the value of z?
Hard149Match each Python operator to its description.
Medium150You 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?
Hard151What is the output of 'print(3 * "ab")'?
Medium152Which function is used to read user input as a string?
Easy153What is the result of 'bool(0) and bool(1)'?
Hard154A 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?
Medium155Which TWO of the following are valid Python variable names?
Medium156A program uses 'x = 3.14' and 'y = int(x)'. What is the value of y?
Medium157Given the code: x = 10; y = 3.0; z = x / y; print(type(z)). What is the output?
Hard158What is the output?
Hard159What is the most appropriate fix for the error shown in the exhibit?
Hard160What is the result of 17 % 5 in Python?
Easy161A 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?
Medium162Which THREE of the following are arithmetic operators in Python?
Hard163A user enters 'Alice' for name and '30' for age. What is the output?
Hard164What does 'print(2 ** 3)' output?
Easy165A 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?
Medium166Which of the following expressions evaluate to True? (Choose three.)
Medium167What is the type of the result of the expression 5 + 3.0?
Easy168Given the code: ```python name = input('Enter your name: ') print('Hello, ' + name) ``` If the user enters 'Alice', what is the output?
Medium169What is the data type of z after executing z = 10 / 2?
Easy170Which FOUR of the following are correct uses of the print() function?
Medium171Order the steps to write a for loop that iterates over a range of numbers.
Medium172Which two of the following are valid Python variable names? (Choose two.)
Medium173A 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?
Easy174A 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?
Medium175After executing: a = 5; b = 2; c = a // b; d = a % b; e = a ** b. What is the value of (c + d) * 2 - e?
Hard176A 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?
Easy177A Python program loads this JSON and accesses the first rule's action. Which expression gives the string "permit"?
Hard178Match each Python data structure to its characteristic.
Medium179What is the data type of the expression (3.14 > 2) and ('a' < 'b')?
Medium180A junior developer writes: print('Hello' + 5). This code raises an error. What is the best way to fix it?
Medium181Refer to the exhibit. What is the output?
Easy182A 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?
Hard183What is the output of the code in the exhibit?
Medium184Which of the following is a valid Python variable name?
Medium185A 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?
Medium186What is the output when the following code is executed? try: print(1/0) except ZeroDivisionError: print("Cannot divide by zero")
Medium187A programmer needs to swap the values of two variables a and b without using a temporary variable. Which approach works in Python?
Medium188A 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?
Medium189Which of the following is NOT a valid variable name in Python?
Easy190What 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?
- Data Types, Variables, Basic I/O and Operators questions test whether you can apply the concept in context, not just recognise a definition.
- How many questions are in this domain?
- This page lists all 190 Data Types, Variables, Basic I/O and Operators questions in the PCEP question bank. The actual exam draws from this domain proportionally to its weighting in the official exam blueprint.
- What is the best way to practise this domain?
- Start with a short focused session (10 questions) to identify gaps, then work through explanations. Repeat with a longer session once the weak areas feel solid.
- Can I practise only Data Types, Variables, Basic I/O and Operators questions?
- Yes — the session launcher on this page filters questions to this domain only. Choose any session length for inline explanations and scoring.