✦ Scientech Easy
Basic Python Test 2
📄
30
Questions
⏱
15 min
Time Limit
⭐
4
Marks / Q
−
1
Negative
✅
70%
Pass Mark
‣ Read each question carefully before answering.
‣ Use the palette to navigate and bookmark questions.
‣ Wrong answers carry negative marks. Skipped = zero.
‣ The quiz auto-submits when the timer reaches zero.
‣ Stay in fullscreen mode throughout the quiz. Exiting fullscreen is detected and will result in auto-submission.
✦ Scientech Easy
Basic Python Test 2
30 Qs
The second argument in open() is the mode. ‘r’ stands for read mode. It opens an EXISTING file for reading only. Other modes: ‘w’ = write (creates/overwrites), ‘a’ = append, ‘x’ = create new file exclusively.
Q 1
1 / 30
0s
What does the following statement do?
[code]
x = open(‘python.csv’, ‘r’)
[/code]
Opens an existing text file named python.csv to read
Opens a new file named python.csv to read
Opens an existing text file named python.csv to write
Opens an existing text file named python.csv to append
Python string indexing starts at 0. So: P=0, y=1, t=2, h=3, o=4, n=5. x[2:4] slices from index 2 up to (but NOT including) index 4, giving characters at index 2 and 3: ‘t’ and ‘h’ → ‘th’.
Q 2
2 / 30
0s
Predict the output of the following Python code:
[code]
x = ‘Python’
print(x[2:4])
[/code]
thon
tho
Pyth
th
Python allows importing multiple modules in a single line by separating them with commas. This statement imports both the ‘keyword’ module (for working with Python keywords) and the ‘sys’ module (for system-level operations) at once.
Q 3
3 / 30
0s
What is the purpose of the following Python statement?
[code]
import keyword, sys
[/code]
Imports the directories named keyword and sys
Imports all the Python keywords
Imports the keyword and sys modules
Imports the keyword and sys functions
math.floor() rounds a number DOWN to the nearest integer and returns an int (not a float). So, math.floor(67.3) returns 67, not 67.0. The math.ceil() would give 68 (rounding up).
Q 4
4 / 30
0s
Predict the output of the following Python code:
[code]
import math
print(math.floor(67.3))
[/code]
67.0
68
67
68.0
del x[:] deletes ALL elements of the list using a full slice, leaving an empty list []. The list object x itself still exists in memory — it is just now empty. This is different from del x, which would delete the variable entirely.
Q 5
5 / 30
0s
What is the output of the following code when executed?
[code]
x = [5, 3, 6, 2, 4, 0, 7]
del x[:]
print(x)
[/code]
[5, 3, 6, 2, 4, 0]
[5, 3, 6, 2, 7]
[]
[4, 0, 7]
Python raises a NameError with the message “name ‘x’ is not defined” when you try to use a variable that has never been assigned a value. Python has no separate “declaration” step — a variable only exists after it is assigned.
Q 6
6 / 30
0s
What type of error occurs when a variable is used without being defined in Python?
Not a variable
Not declared
Not assigned
Not defined
x[0] is 4 and x[1] is 0. str(4) gives ‘4’ and str(0) gives ‘0’. Concatenating the two strings ‘4’ + ‘0’ gives ’40’ (not the integer 4, and not the sum 4 + 0 = 4). This is string concatenation, not arithmetic addition.
Q 7
7 / 30
0s
What will be the output after executing the following statements?
[code]
x = [4, 0, 7]
y = str(x[0]) + str(x[1])
print(y)
[/code]
11
4
7
40
A Python Dictionary (dict) stores data as key-value pairs, e.g. {‘name’: ‘Alice’, ‘age’: 25}. Lists store ordered sequences by index. Tuples are ordered and immutable. Sets store unique unordered values with no keys.
Q 8
8 / 30
0s
What is the data type used to store values in key-value pairs?
Set
List
Tuple
Dictionary
Since ‘b’ has never been assigned a value, Python cannot find it in any scope. This raises a NameError: “name ‘b’ is not defined”. SyntaxError is for invalid code structure; TypeError is for wrong type operations; ValueError is for correct type but invalid value.
Q 9
9 / 30
0s
What type of error will be raised by the following Python statement?
[code]
a = b
[/code]
SyntaxError
TypeError
NameError
ValueError
The ‘+’ operator on strings performs concatenation with no spaces added automatically. Since x = ‘Python’ and y = ‘MCQ’ have no spaces, joining them gives ‘PythonMCQ’. To get ‘Python MCQ’, you would write x + ‘ ‘ + y.
Q 10
10 / 30
0s
What will be printed when the following code is executed?
[code]
x = ‘Python’
y = ‘MCQ’
print(x + y)
[/code]
PythonMCQ
Python Python
Python MCQ
MCQ MCQ
Strings in Python are immutable — methods like .lower() do NOT modify the original string. They return a NEW string. Since the result of x.lower() is not stored anywhere, x still holds ‘Python Jobs’. To get lowercase, you need: x = x.lower().
Q 11
11 / 30
0s
What is the output of the following Python code?
[code]
x = ‘Python Jobs’
x.lower()
print(x)
[/code]
Python jobs
python jobs
PYTHON JOBS
Python Jobs
You cannot concatenate a string and an integer using the + operator.
Option B raises a TypeError.
Options A and D are valid because string × integer performs repetition.
Option C works because the integer is converted to a string.
Q 12
12 / 30
0s
In Python, one of the following statements will produce an error. Which one?
x = ‘Hello’ * 2
x = ‘Hello’ + 3
x = ‘Hello’ * int(‘2’)
x = ‘Hello’ + str(3)
You cannot concatenate a string and an integer directly in Python. ‘python’ + 1 raises a TypeError because the ‘+’ operator requires both sides to be the same type. Option A works because int(‘1’) gives 1 (an integer), and string * integer is valid repetition. Option C converts 1 to ‘1’ first, so string + string is fine. Option D is also valid string repetition.
Q 13
13 / 30
0s
Which of the following Python statements will result in an error when executed?
P = ‘python’ + str(1)
P = ‘python’ * 1
P = ‘python’ + 1
P = ‘python’ * int(‘1’)
Python’s four core built-in data structures are List, Dictionary, Tuple, and Set. A Module is a file containing Python code (functions, classes, variables) that can be imported — it is not a data structure.
Q 14
14 / 30
0s
Which of the following is not a core data structure in Python?
Dictionary
Tuple
List
Module
y = x does NOT create a copy — both y and x point to the SAME list object in memory. So y[1] = 6 also changes x[1]. The list was [4, 5, 7, 8, 9]; changing index 1 from 5 to 6 gives [4, 6, 7, 8, 9]. To copy, use y = x.copy() or y = x[:].
Q 15
15 / 30
0s
What is the result of executing the following code snippet?
[code]
x = [4, 5, 7, 8, 9]
y = x
y[1] = 6
print(y)
[/code]
[4, 6, 7, 8, 9]
[4, 7, 8, 9]
[4, 5, 7, 8, 9]
[4, 5, 6, 7, 8, 9]
int() expects a string that represents a valid integer (like ‘5’ or ’42’). ‘hello’ is a valid string (correct type), but its value cannot be converted to an integer. This raises a ValueError: “invalid literal for int() with base 10: ‘hello'”.
Q 16
16 / 30
0s
What type of error occurs when the following statement is executed in Python?
[code]
a = int(‘hello’)
[/code]
SyntaxError
NameError
TypeError
ValueError
x is a List → tuple(x) converts it to a Tuple stored in y → list(y) converts it BACK to a List stored in z. So z ends up as [1, 2, 3, 4], a List. No error occurs because these conversions are all valid.
Q 17
17 / 30
0s
What will be the data type of z after executing the following statements?
[code]
x = [1, 2, 3, 4]
y = tuple(x)
z = list(y)
[/code]
String
List
TypeError
Tuple
Python’s built-in regular expression module is simply named ‘re’. You use it as: import re, then re.search(), re.match(), re.findall(), etc. There is also a third-party ‘regex’ module with extra features, but the built-in one is ‘re’.
Q 18
18 / 30
0s
What is the name of Python’s built-in module for regular expressions?
regexes
REG
regex
re
The ‘+’ operator cannot combine a string and an integer because they are incompatible types. Python raises a TypeError: “can only concatenate str (not ‘int’) to str”. Unlike some other languages, Python does not auto-convert types during operations.
Q 19
19 / 30
0s
Identify the error in the following code:
[code]
a = ‘Python’ + 3
[/code]
SyntaxError
ValueError
TypeError
NameError
Python string membership checks are case-sensitive. ‘p’ (lowercase) is NOT the same as ‘P’ (uppercase). Since ‘Python’ contains ‘P’ but not ‘p’, the expression ‘p’ not in x evaluates to True.
Q 20
20 / 30
0s
What will be the output of the following code?
[code]
x = ‘Python’
print(‘p’ not in x)
[/code]
p
P
False
True
4*3=12, 60//5=12, 17-5=12 all produce the integer 12. However, 12/1 uses true division and produces 12.0 (a float), not the integer 12. That’s the odd one out.
Q 21
21 / 30
0s
Which of the following Python expressions produces a different type of result compared to the others?
17-5
12/1
4*3
60//5
‘shutil’ (short for “shell utilities”) is Python’s built-in module for high-level file and directory operations such as copying, moving, renaming, and deleting files/folders. Example: shutil.copy(), shutil.move(), shutil.rmtree().
Q 22
22 / 30
0s
What is the name of Python’s built-in module for high-level file operations?
shutil
fileutil
fileop
futility
The curly brace ‘{‘ is opened but closed with a round bracket ‘)’ instead of ‘}’. This is a mismatched bracket, which Python detects before even running the code. It raises a SyntaxError because the code structure itself is invalid.
Q 23
23 / 30
0s
Identify the error in the following code:
[code]
a = {7)
[/code]
TypeError
NameError
ValueError
SyntaxError
Python’s built-in ‘ipaddress’ module provides tools for creating, manipulating, and validating IPv4 and IPv6 addresses and networks. Example: import ipaddress followed by ipaddress.IPv4Address(‘192.168.1.1’).
Q 24
24 / 30
0s
What is the name of Python’s built-in module for IPv4/IPv6 manipulation?
ip
ipaddress
ipman
getip
math.sqrt() always returns a float, even when the result is a whole number. So math.sqrt(4) returns 2.0, not the integer 2. To get an integer result, you would need int(math.sqrt(4)).
Q 25
25 / 30
0s
What is the result of executing the following code snippet?
[code]
import math
print(math.sqrt(4))
[/code]
2.0
2.1
2
4.0
‘import random’ loads Python’s built-in ‘random’ module into the current program. It imports the entire module (not just one function), giving access to functions like random.random(), random.randint(), etc.
Q 26
26 / 30
0s
What is the purpose of the following Python statement?
[code]
import random
[/code]
Imports the random function
Imports the directory named random
Imports a random module from a list of modules
Imports the random module
The .format() method replaces {} placeholders in order with the provided arguments. The first {} is replaced by ‘Python’, the literal ‘ 3 ‘ stays, and the second {} is replaced by ‘Test’, giving ‘Python 3 Test’.
Q 27
27 / 30
0s
What is the result of executing the following code snippet?
[code]
x = ‘{} 3 {}’.format(‘Python’, ‘Test’)
print(x)
[/code]
Test 3 Python
Python 3 Test
Python Test
Test Python
Q 28
28 / 30
0s
What will be the output after the following statements?
[code]
a = 0
b = 5
c = 10
a = b
b = c
c = a
print(a, b, c)
[/code]
0 5 10
5 10 10
5 5 10
5 10 5
x = ‘Python ‘ contains a trailing space after Python. Multiplying a string by 3 repeats the entire string (including the space) three times, giving ‘Python Python Python ‘ — which displays as Python Python Python (with trailing space).
Q 29
29 / 30
0s
What is the output of the following Python code?
[code]
x = ‘Python ‘
print(x*3)
[/code]
Pyt Pyt Pyt
PythonPythonPython
Python Python Python
t
(‘Python’) is not a tuple — it is just a string in parentheses. To create a single-element tuple, a trailing comma is required: (‘Python’,). Since no comma is present, x is simply the string ‘Python’, and print(x) outputs Python without quotes.
Q 30
30 / 30
0s
What will be the output of the following code?
[code]
x = (‘Python’)
print(x)
[/code]
P y t h o n
(‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’)
Python
(‘Python’)
Time Left
00 : 15 : 00
Question Palette
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Answered
Bookmarked
Not Visited
Finish Test?
You cannot change responses after submission.
⏱ Time's Up!
Your time is up. The quiz will be submitted.
⚠ Fullscreen Mode Exited
Quiz Complete!
Basic Python Test 2
Your Score
Correct
Wrong
Skipped
Total Q
Time Taken





