Page 1 of 3

Forward College - Python Aptitude Quiz

1. What is the output of the following code?

x = [1, 2, 3] y = x y.append(4) print(len(x)
1. What is the output of the following code?
A
B
C
D

2. Which of the following is the correct way to create a dictionary in Python?

2. Which of the following is the correct way to create a dictionary in Python?
A
B
C
D

3. What does the enumerate() function return when iterating over a list?

3. What does the enumerate() function return when iterating over a list?
A
B
C
D

4. What is the result of: [x**2 for x in range(5) if x % 2 == 0]

4. What is the result of: [x**2 for x in range(5) if x % 2 == 0]
A
B
C
D

5. Which method is used to remove and return the last element from a list?

5. Which method is used to remove and return the last element from a list?
A
B
C
D

6. Which Pandas function is used to read a CSV file?

6. Which Pandas function is used to read a CSV file?
A
B
C
D

7. What does df.dropna() do in Pandas?

7. What does df.dropna() do in Pandas?
A
B
C
D

8. How do you select rows where the 'age' column is greater than 30 in a DataFrame df?

8. How do you select rows where the 'age' column is greater than 30 in a DataFrame df?
A
B
C
D

9. What is the difference between df.loc[] and df.iloc[]?

9. What is the difference between df.loc[] and df.iloc[]?
A
B
C
D

10. Which method is used to combine two DataFrames vertically (row-wise)?

10. Which method is used to combine two DataFrames vertically (row-wise)?
A
B
C
D

11. What does df.groupby('category').mean() return?

11. What does df.groupby('category').mean() return?
A
B
C
D

12. How do you rename columns in a Pandas DataFrame?

12. How do you rename columns in a Pandas DataFrame?
A
B
C
D

13. Which function is used to display a plot in Matplotlib?

13. Which function is used to display a plot in Matplotlib?
A
B
C
D

14. What does plt.figure(figsize=(10, 6)) do?

14. What does plt.figure(figsize=(10, 6)) do?
A
B
C
D

15. Which function creates a bar chart in Matplotlib?

15. Which function creates a bar chart in Matplotlib?
A
B
C
D

16. Which Seaborn function is best for visualizing the distribution of a single variable?

16. Which Seaborn function is best for visualizing the distribution of a single variable?
A
B
C
D

17. What parameter in Seaborn functions is used to color data points by a categorical variable?

17. What parameter in Seaborn functions is used to color data points by a categorical variable?
A
B
C
D

18. Scenario: A student is trying to remove all "Done" items from their task list. Their current for loop is skipping items because the list size changes during iteration. Prompt: Rewrite the assignment for tasks using a list comprehension to correctly filter out all items that are "Done". tasks = ["Done", "Done", "Pending", "Done", "Pending"] # Write a single line of code to redefine 'tasks' correctly: tasks =

18. Scenario: A student is trying to remove all "Done" items from their task list. Their current for loop is skipping items because the list size changes during iteration. Prompt: Rewrite the assignment for tasks using a list comprehension to correctly filter out all items that are "Done". tasks = ["Done", "Done", "Pending", "Done", "Pending"] # Write a single line of code to redefine 'tasks' correctly: tasks =
A
B
C
D

19. The goal is to filter the DataFrame to show only rows where 'Score' is greater than 80 AND 'Attendance' is greater than 90. The code below causes a ValueError. How should the last line be written to fix the error? import pandas as pd df = pd.DataFrame({ 'Student': ['Sam', 'Mia', 'Jay'], 'Score': [85, 92, 78], 'Attendance': [95, 88, 92] }) # BUG: This line throws a ValueError passed = df[(df['Score'] > 80) and (df['Attendance'] > 90)]

19. The goal is to filter the DataFrame to show only rows where 'Score' is greater than 80 AND 'Attendance' is greater than 90. The code below causes a ValueError. How should the last line be written to fix the error? import pandas as pd df = pd.DataFrame({ 'Student': ['Sam', 'Mia', 'Jay'], 'Score': [85, 92, 78], 'Attendance': [95, 88, 92] }) # BUG: This line throws a ValueError passed = df[(df['Score'] > 80) and (df['Attendance'] > 90)]
A
B
C
D

20. Review the code snippet below. The developer intends to access the first row of the DataFrame (the row containing "Apple"). What will be the actual result of running this code ? import pandas as pd data = {'Fruit': ['Apple', 'Banana', 'Cherry'], 'Price': [1.2, 0.8, 2.5]} # Note the custom index starting at 10 df = pd.DataFrame(data, index=[10, 20, 30]) # Attempting to get the first row print(df.loc[0])

20. Review the code snippet below. The developer intends to access the first row of the DataFrame (the row containing "Apple"). What will be the actual result of running this code ? import pandas as pd data = {'Fruit': ['Apple', 'Banana', 'Cherry'], 'Price': [1.2, 0.8, 2.5]} # Note the custom index starting at 10 df = pd.DataFrame(data, index=[10, 20, 30]) # Attempting to get the first row print(df.loc[0])
A
B
C
D