Font size
WorksheetsChapter 1 to Chapter 5 python
Total questions: 45
Worksheet time: 49mins
What symbol is used to write a single-line comment in Python?
//
<!--
#
/*
Which of the following best describes the difference between Python 2 and Python 3?
Python 3 is just a faster version of Python 2.
Python 2 uses print as a function, while Python 3 uses print as a statement.
Python 3 uses print as a function, while Python 2 uses print as a statement.
Python 2 supports more libraries than Python 3.
Write a simple python program to remove duplicate elements from a list.
Input: [1, 2, 2, 3, 4, 4, 5]
Output: [1, 2, 3, 4, 5]
Which of the following is the correct extension of a Python file?
.pyth
.pt
.py
.p
Which keyword is used to define a function in Python?
function
def
fun
define
What is the output of: print(type("Hello"))
<type 'string'>
<class 'int'>
<class 'str'>
str
Which of the following is not a valid Python data type?
array
tuple
list
dictionary
What will be the output of print(2 ** 3)?
(a)
Which of the following is used to take input from the user in Python 3?
(a)
Which symbol is used for multiplication in Python?
(a)
Which one of the following is a mutable data type in Python?
tuple
string
list
int
Why is indentation important in Python?
It makes the code look pretty
It is used to define blocks of code
It helps Python ignore errors
It is optional in Python
Which of the following Python scripts correctly asks for a user's name and prints a greeting?
name = input("Enter your name")
print("Hello" + name)
name = get("Enter your name")
print("Hello", name)
input("What is your name?") = name
print("Hi", name)
ask name = input("Enter name")
echo("Hi", name)
Which of the following is a valid variable name in Python?
2ndValue
value 2
my-value
_class2
Which code snippet checks if a number is less than 10 and prints “Smaller”?
if x > 10:
print("Smaller")
if x < 10:
print("Smaller")
if x == 10:
print("Smaller")
if x != 10:
print("Smaller")
What will be the output of the following code?
(a)
Which of the following correctly swaps the values of a and b?
temp = a
b = a
a = temp
a = b
b = a
a, b = b, a
swap(a, b)
What is the data type of the result of: 7 \\ 2?
int
float
str
double
What will be the value of x after the following code?
x = 10
x += 5
x -= 3
(a)
What is the output of this code?
x = 2
y = 3
x *= y + 1
print(x)
(a)
Which of these best describes a statement in Python?
A block of text
A print function
A line of code that performs an action
A set of rules
Predict the output of:
a = 4
b = a + 2
a = b - 1
print(a)
(a)
Given x = 10, what will print(x % 3) output?
(a)
Which keyword is used to create a decision-making structure in Python?
select
when
if
switchs
What is the correct syntax for an if-else statement in Python?
if condition:
if condition then:
if (condition) then
if: condition
Which of the following correctly checks if x is between 10 and 20 (inclusive)?
10 <= x <= 20
x >= 10 and x <= 20
x => 10 and x =< 20
x <= 10 or x <= 20
Which keyword is used to check multiple conditions in sequence?
elseif
when
elif
else if
What is the output of this code?
x = 3
if x % 2 == 0:
print("Even")
else:
print("Odd")
(a)
What is the output?
score = 75
if score >= 90:
grade = "A"
elif score >= 70:
grade = "B"
else:
grade = "C"
print(grade)
(a)
Which of the following statements about indentation in Python is true?
Indentation is optional in if statements
Indentation is only required in loops
Indentation is required to define blocks in Python
Python uses {} for blocks instead of indentation
What is the output of:
(a)
What is the result of the condition: not (5 > 3)?
(a)
What is the logical error in the following code?
Incorrect use of elif
All conditions are checked regardless of earlier ones
The last elif will never run
The structure is correct; no error
You want to check if a number is not between 10 and 20. Which condition is best?
if x < 10 or x > 20:
if x > 10 and x < 20:
if x <= 20 or x >= 10:
if x != 10 and x != 20:
Which condition checks if a variable x is either 0 or a multiple of 5?
if x == 0 or x % 5 != 0:
if x == 0 and x % 5 == 0:
if x == 0 or x % 5 == 0:
if x % 5 == 0:
What is the output of this nested if statement?
(a)
Identify the issue in this conditional:
Which structure is best to check multiple exclusive ranges?
Only if statements
if, elif, and else
if and else only
Nested if inside a loop
What happens if you omit the colon in an if statement?
Prints nothing
Logical error
SyntaxError
RuntimeError
Which output is correct for this?
(a)
Analyze the following code. The goal is to check if a number is positive, negative, or zero, but the output is incorrect when the number is 0. Identify the logic error and fix the code.
Examine the following code. It is intended to calculate the total cost after tax, but the result is wrong. Identify the mistake and correct it.
This program is meant to check if a number is divisible by both 3 and 5, but it always prints "Not divisible". Analyze and correct the logic.
This program intends to swap two numbers without using a third variable. Analyze the logic and explain if it's correct.
Analyze the following expression. What will be the output, and why might this confuse beginners?
