USER
1.
Question 1
Python is an interpreted language. Which of the following statements correctly describes an interpreted language?
The source code is pre-built and compiled before running.
Python needs to be built prior to it being run.
Python will save all code first prior to running.
The source code is converted into bytecode that is then executed by the Python virtual machine.
1 point
2.
Question 2
Why is indentation important in Python?
The code will compile faster with indentation.
Python used indentation to determine which code block starts and ends.
It makes the code more readable.
The code will be read in a sequential manner
1 point
3.
Question 3
What will be the output of the following code?
123
names = ["Anna", "Natasha", "Mike"]
names.insert(2, "Xi")
print(names)
[“Anna”, “Natasha”, Xi]
[“Anna”, “Natasha”, 2, “Xi”, “Mike”]
[“Anna”, “Xi”, ”Mike” ]
[“Anna”, “Natasha”, “Xi”, “Mike”]
1 point
4.
Question 4
What will be the output of the code below?
12
for x in range(1, 4):
print(int((str((float(x))))))
1.0, 2.0
1 , 2
“one”, “two”
Will give an error
1 point
5.
Question 5
What will be the output of the following code:
123
sample_dict = {1: 'Coffee', 2: 'Tea', 3: 'Juice'}
for x in sample_dict:
print(x)
1 2 3
(1, 'Coffee')
(2, 'Tea')
(3, 'Juice')
{1 2 3}
‘Coffee’, ‘Tea’, ‘Juice’
1 point
6.
Question 6
What will be the output of the recursive code below?
1234567
def recursion(num):
print(num)
next = num - 3
if next > 1:
recursion(next)
recursion(11)
11 8 5 2
2 5 8 11
2 5 8
8 5 2
1 point
7.
Question 7
What will be the type of time complexity for the following piece of code:
12345
def bigo(numbers):
for i in numbers:
print(numbers)
bigo([1, 7, 13, 19])
Quadratic Time
Logarithmic Time
Constant Time
Linear Time
1 point
8.
Question 8
What will be the output of the code below:
12345
str = 'Pomodoro'
for l in str:
if l == 'o':
str = str.split()
print(str, end=", ")
['Pomodoro']
[‘P’, ‘m’, ‘d’, ‘o’]
[‘Pomodoro’, ‘modoro’, ‘doro‘, ‘ro’]
Will throw an error
1 point
9.
Question 9
Find the output of the code below:
12345678910
def d():
color = "green"
def e():
nonlocal color
color = "yellow"
e()
print("Color: " + color)
color = "red"
color = "blue"
d()
red
blue
green
yellow
1 point
10.
Question 10
Find the output of the code below:
123456789101112131415161718
num = 9
class Car:
num = 5
bathrooms = 2
def cost_evaluation(num):
num = 10
return num
class Bike():
9
5
10
2
1 point
11.
Question 11
Which of the following is the correct implementation that will return True if there is a parent class P, with an object p and a sub-class called C, with an object c?
print(issubclass(C,P))
print(issubclass(C,c))
print(issubclass(p,C))
print(issubclass(P,C))
1 point
12.
Question 12
Django is a type of:
Asynchronous framework
Full-stack framework
Micro-framework
1 point
13.
Question 13
Which of the following is not true about Integration testing:
Primarily dealt by the tester.
Tests the flow of data from one component to another.
It combines unit tests.
It is where the application is tested as a whole.
1 point
14.
Question 14
While using pytest for testing, it is necessary to run the file containing the main code before we can run the testing file containing our unit tests.
True
False
1 point
15.
Question 15
What will be the output of the code below:
12345678910111213141516
class A:
def a(self):
return "Function inside A"
class B:
def a(self):
return "Function inside B"
class C:
pass
No output
None of the above
Function inside B
Function inside A
1 point
ASSISTANT
Below are the correct answers, with explanations:
---
#### **Question 1:**
**Python is an interpreted language. Which of the following statements correctly describes an interpreted language?**
**Correct Answer:**
**The source code is converted into bytecode that is then executed by the Python virtual machine.**
**Explanation:**
Python is an interpreted language that compiles the source code into bytecode, which is then executed by the Python interpreter or the Python Virtual Machine (PVM). It doesn't require building or compiling the code beforehand like traditional compiled languages (e.g., C or C++).
---
#### **Question 2:**
**Why is indentation important in Python?**
**Correct Answer:**
**Python uses indentation to determine which code block starts and ends.**
**Explanation:**
Indentation in Python is not just for readability; it's mandatory to define code blocks (e.g., inside a function, `if` statement, loop, etc.). Without proper indentation, Python will throw an `IndentationError`.
---
#### **Question 3:**
**What will be the output of the following code?**
```python
names = ["Anna", "Natasha", "Mike"]
names.insert(2, "Xi")
print(names)
```
**Correct Answer:**
**[“Anna”, “Natasha”, “Xi”, “Mike”]**
**Explanation:**
The `insert()` function inserts an element at the specified index. In this case, `"Xi"` is inserted at index `2`, shifting the remaining elements to the right.
---
#### **Question 4:**
**What will be the output of the code below?**
```python
for x in range(1, 4):
print(int((str((float(x))))))
```
**Correct Answer:**
**Will give an error**
**Explanation:**
The outermost `int()` function converts the argument into an integer, but the outer structure has incorrect nesting, as `range` itself isn't properly processed. Properly structured, this would have printed `1`, `2`, `3`. The current snippet will result in an error.
---
#### **Question 5:**
**What will be the output of the following code?**
```python
sample_dict = {1: 'Coffee', 2: 'Tea', 3: 'Juice'}
for x in sample_dict:
print(x)
```
**Correct Answer:**
**1 2 3**
**Explanation:**
When iterating through a dictionary, the default iteration is over the keys of the dictionary (`1`, `2`, `3`). If you need both keys and values, you use `.items()`.
---
#### **Question 6:**
**What will be the output of the recursive code below?**
```python
def recursion(num):
print(num)
next = num - 3
if next > 1:
recursion(next)
recursion(11)
```
**Correct Answer:**
**11 8 5 2**
**Explanation:**
The recursion reduces the input by `3` on each call until the result is no greater than `1`. The sequence of numbers printed is `11 → 8 → 5 → 2`.
---
#### **Question 7:**
**What will be the type of time complexity for the following piece of code?**
```python
def bigo(numbers):
for i in numbers:
print(numbers)
bigo([1, 7, 13, 19])
```
**Correct Answer:**
**Linear Time**
**Explanation:**
The code iterates through the entire list `numbers`, and the time taken is proportional to the number of elements. This results in **O(n)**, or linear time complexity.
---
#### **Question 8:**
**What will be the output of the code below?**
```python
str = 'Pomodoro'
for l in str:
if l == 'o':
str = str.split()
print(str, end=", ")
```
**Correct Answer:**
**Will throw an error**
**Explanation:**
The string `str` is overwritten by `str.split()` inside the loop, resulting in a change of type from string to list. On the next iteration, it'll cause an error when attempting to iterate over a list.
---
#### **Question 9:**
**Find the output of the code below:**
```python
def d():
color = "green"
def e():
nonlocal color
color = "yellow"
e()
print("Color: " + color)
color = "red"
color = "blue"
d()
```
**Correct Answer:**
**yellow**
**Explanation:**
The `nonlocal` keyword modifies the `color` variable inside the `e()` function, changing it to `"yellow"`. The `print` statement reflects this updated value—`"yellow"`—before the variable is reassigned to `"red"` later on.
---
#### **Question 10:**
**Find the output of the code below:**
```python
num = 9
class Car:
num = 5
bathrooms = 2
def cost_evaluation(num):
num = 10
return num
class Bike():
pass
```
**Correct Answer:**
**9**
**Explanation:**
The global variable `num` remains `9`, and it is unaffected by the local `num` redefined in `cost_evaluation`. No method is called to alter its value.
---
#### **Question 11:**
**Which of the following is the correct implementation that will return True if there is a parent class `P`, with an object `p` and a subclass `C`, with an object `c`?**
**Correct Answer:**
**`print(issubclass(C, P))`**
**Explanation:**
The `issubclass()` function checks if a class is a subclass of another class. It is applied to classes (`C`, `P`), not objects (`p`, `c`).
---
#### **Question 12:**
**Django is a type of:**
**Correct Answer:**
**Full-stack framework**
**Explanation:**
Django is a full-stack web framework for Python that provides tools for both the front-end (templates) and back-end (database models, request handling). It isn't a micro-framework (like Flask) or purely asynchronous.
---
#### **Question 13:**
**Which of the following is not true about Integration testing?**
**Correct Answer:**
**It is where the application is tested as a whole.**
**Explanation:**
Integration testing focuses on testing the interactions between different components or units of a program. **Testing the application as a whole** is actually the goal of system testing, not integration testing.
---
#### **Question 14:**
**While using pytest for testing, it is necessary to run the file containing the main code before we can run the testing file containing our unit tests.**
**Correct Answer:**
**False**
**Explanation:**
Pytest automatically runs the unit test files without requiring the main code file to be executed first. The test suite and the code logic are independent.
---
#### **Question 15:**
**What will be the output of the code below?**
```python
class A:
def a(self):
return "Function inside A"
class B:
def a(self):
return "Function inside B"
class C:
pass
```
**Correct Answer:**
**No output**
**Explanation:**
The program declares three classes (`A`, `B`, `C`) but does not execute or print anything. Without instantiation or method calls, there is no output.
---