Python Basics Assessment :Inferential Statistical Analysis with Python (Statistics with Python Specialization) Answers 2025
1. Question 1
Default for axis in pandas.DataFrame.drop
-
The default is axis=0
-
✅ 0
-
❌ any other value
Explanation:DataFrame.drop() by default drops rows, meaning axis=0.
2. Question 2
Default kind for np.sort
-
⚙️ Default = ‘quicksort’
-
❌ stable
-
✅ quicksort
-
❌ mergesort
-
❌ heapsort
Explanation:
NumPy’s default algorithm for np.sort is quicksort.
3. Question 3
What does the function return?
def get_element(lst):
new_lst = []
for i in lst:
new_lst.append(i**2)
return lst[1]
Because return is inside the loop, the function returns immediately on the first iteration, returning lst[1].
For lst = [1, 7, 3, 5] → lst[1] = 7.
-
❌ 1
-
❌ 3
-
❌ 9
-
✅ 7
-
❌ 25
-
❌ 49
Explanation:
The return executes on the first loop iteration and returns the second element of the list.
4. Question 4
my_dict = {'peaches':'cream', 'cat':'dog', 'this one':'that one'}
my_dict['this one']
-
The value for key
'this one'is'that one'. -
❌ entire dict
-
❌ ‘dog’
-
❌ {‘that one’}
-
✅ ‘that one’
-
❌ ‘peaches’
Explanation:
Dictionary lookup returns the value of the key.
5. Question 5
Keys of my_dict:
'peaches', 'cat', 'this one'
-
✅ ‘peaches’, ‘cat’, ‘this one’
-
❌ peaches, cat, this one (missing quotes)
-
❌ ‘cream’, ‘dog’, ‘that one’
-
❌ cream, dog, that one
Explanation:
Keys are the left-side values in key:value pairs.
6. Question 6
Values of my_dict:
'cream', 'dog', 'that one'
Correct options:
-
✅ ‘cream’, ‘dog’, ‘that one’
-
❌ ‘peaches’, ‘that one’, ‘cat’
-
❌ ‘cream’, ‘dog’, ‘cat’
-
❌ ‘cream’, ‘dog’, ‘this one’
Explanation:
Values are the right-hand side of each key:value pair.
7. Question 7
What happens when calling save_plot(x, y)?
plt.plot(x, y)
plt.savefig('new_plot')
-
The plot is created and saved to a file.
-
✅ A plot is outputted and saved as ‘new_plot’.
-
❌ The function returns a plot
-
❌ nothing
-
❌ y
Explanation:plt.savefig writes the generated plot to a file. The function itself returns None.
🧾 Summary Table
| Q# | Correct Answer | Key Concept |
|---|---|---|
| 1 | 0 | Default axis in DataFrame.drop |
| 2 | quicksort | Default sort method |
| 3 | 7 | Return inside loop |
| 4 | ‘that one’ | Dict key lookup |
| 5 | ‘peaches’, ‘cat’, ‘this one’ | Dictionary keys |
| 6 | ‘cream’, ‘dog’, ‘that one’ | Dictionary values |
| 7 | Plot saved as ‘new_plot’ | matplotlib behavior |