Unit 6: Real-world applications - Practice Quiz
1 Which Python library is primarily used for computer vision and image processing tasks?
2 Which function is used to read an image from a file in OpenCV?
cv2.showImage()
cv2.imread()
cv2.openImage()
cv2.loadFile()
3 In OpenCV, which color format are images loaded in by default?
4 Which OpenCV function displays an image in a window?
cv2.view()
cv2.display()
cv2.imshow()
cv2.render()
5 PyGame is a Python library mainly used for creating what type of applications?
6 Which function must be called to start using PyGame's modules?
pygame.init()
pygame.start()
pygame.run()
pygame.begin()
7 In PyGame, which object represents the main window or drawing surface?
8 Which PyGame concept is typically used to continuously update the game and handle events?
9 Which Python library is commonly used to send HTTP requests to access a URL?
requests
numpy
pygame
turtle
10 Which library is widely used to parse HTML content during web scraping?
11 What does the term "web scraping" mean?
12
An HTTP status code of 200 typically indicates what?
13 Which Python library is one of the most widely used for creating basic plots and charts?
14 Which chart type is best suited for showing trends in data over time?
15 Which library is built on top of Matplotlib and provides attractive statistical graphics?
16 Which chart is most appropriate for showing the proportion of parts to a whole?
17 Which library is commonly used for numerical computing and working with arrays in Python?
18 Which Python library is primarily used for data analysis and handling tabular data?
19 Which of the following is a real-world application where Python is commonly used?
20 In the context of data, what does "data storytelling" mainly involve?
21
In OpenCV, when you read an image using cv2.imread(), in what channel order are the pixel values stored by default?
22
You want to convert a color image img to grayscale in OpenCV. Which line accomplishes this?
gray = cv2.imread(img, 0)
gray = cv2.grayscale(img)
gray = cv2.convert(img, GRAY)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
23
What does the shape attribute img.shape return as (480, 640, 3) indicate about the image?
24 In a typical PyGame program, which function must be called first to start up all imported PyGame modules?
pygame.begin()
pygame.init()
pygame.run()
pygame.start()
25 Inside a PyGame main loop, which call is responsible for actually updating the full screen with everything drawn?
pygame.event.get()
pygame.display.init()
pygame.screen.draw()
pygame.display.flip()
26
Why is pygame.time.Clock() combined with clock.tick(60) used in a game loop?
27 In PyGame, how do you typically detect that the user clicked the window's close button?
pygame.display.quit() repeatedly
pygame.KEYDOWN
event.type == pygame.QUIT in the event loop
pygame.window.closed()
28 When scraping a webpage in Python, which combination is most commonly used to fetch the HTML and then parse it?
urllib to parse, requests to fetch
BeautifulSoup to fetch, requests to parse
json to fetch, csv to parse
requests to fetch, BeautifulSoup to parse
29
After response = requests.get(url), which attribute do you check to confirm the request succeeded (HTTP 200)?
response.result
response.status_code
response.success
response.ok_flag
30
Using BeautifulSoup, which method returns a list of all <a> anchor tags on a page?
soup.get('a')
soup.select_one('a')
soup.find_all('a')
soup.find('a')
31
A website's robots.txt disallows scraping certain paths. What is the correct interpretation for a responsible scraper?
32 In Matplotlib, which plot type is most appropriate for showing the relationship between two continuous numeric variables?
33 You want to visualize the distribution and frequency of a single continuous variable such as exam scores. Which chart is best?
34
In Matplotlib, what is the purpose of calling plt.show() at the end of a plotting script?
35 Which library is built on top of Matplotlib and provides high-level functions for attractive statistical graphics?
36 Which Python library is primarily used for numerical computing with efficient multi-dimensional array operations?
37 A data analyst needs to load a CSV file into a labeled, tabular data structure with columns. Which library and object are most appropriate?
matplotlib Figure
requests Session
pandas DataFrame
numpy scalar
38 Which pair correctly matches a Python toolbox to its main purpose?
39 A team builds a Python system that detects faces in a live camera feed. Which library is the natural core of this application?
40 A company wants to automatically collect daily product prices from several e-commerce sites into a spreadsheet for analysis. Which workflow best fits?
41
In OpenCV, you load an image with cv2.imread('img.png') and display it using Matplotlib's plt.imshow(). The colors appear distorted (blues look red). What is the root cause and correct fix?
cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
cv2.IMREAD_UNCHANGED
cv2.COLOR_BGR2GRAY
42 You apply a averaging (box) blur kernel to an image, then apply the same kernel again. Compared to a single box blur, the two-pass approach:
43
When performing edge detection with cv2.Canny(img, threshold1, threshold2), what best describes the role of the two thresholds in hysteresis?
threshold1 sets Gaussian blur size and threshold2 sets the gradient magnitude
threshold1 are strong edges; those above threshold2 are discarded as noise
threshold2 are strong edges; pixels between the thresholds become edges only if connected to strong edges
44
In a PyGame loop, a developer moves a sprite by adding a fixed number of pixels each frame without using clock.tick(). On faster hardware the object moves too quickly. What is the correct fix?
pygame.display.flip() twice per loop iteration
45 A PyGame program's window becomes unresponsive and shows "Not Responding" during gameplay. Which omission most likely causes this?
clock.tick(30)
pygame.event.get() or pygame.event.pump()
46 For pixel-perfect collision between two moving sprites in PyGame, which approach is most accurate but computationally heavier than rectangle collision?
pygame.mask.from_surface and mask.overlap
rect.colliderect on both sprites
pygame.sprite.spritecollide with collided=None
47
You scrape a page with requests.get(url) and BeautifulSoup, but the target data is missing from the returned HTML even though it appears in the browser. What is the most probable reason?
requests does not execute
<div> tags without the lxml parser
requests strips all dynamic tags from the response by default
48
Which statement about robots.txt and web scraping is most accurate?
49 A scraper repeatedly hits a site and starts receiving HTTP 429 responses. Which combination best addresses this while remaining respectful?
Retry-After header
50 You plot data spanning to on a linear y-axis and small values become invisible near zero. Which change best reveals structure across all magnitudes?
plt.yscale('log'))
51 When designing a chart for viewers who may be color-blind, which practice is most effective?
52 A bar chart of average sales per region hides the fact that one region has a bimodal distribution. Which visualization better exposes this within-group structure?
53
In Matplotlib, what is the key difference between the stateful pyplot interface and the object-oriented (Axes) interface for complex multi-panel figures?
plt.figure()
Axes object, avoiding ambiguity about which subplot commands affect
pyplot interface renders faster because it caches figures
pyplot interface supports saving figures to file
54
You perform an element-wise operation on two large arrays. Why is NumPy vectorization typically much faster than a Python for loop?
for loops cannot operate on numeric data
55
A Pandas operation df[df['a'] > 0]['b'] = 5 produces a SettingWithCopyWarning and the change may not persist. What is the correct fix?
.loc for combined selection and assignment: df.loc[df['a'] > 0, 'b'] = 5
df.copy() before assigning
pd.options.mode.chained_assignment = None
56
When training a scikit-learn model, why should scaling (e.g., StandardScaler) be fit only on the training data and not on the full dataset before splitting?
57 In data storytelling, a stakeholder audience needs to grasp one key takeaway quickly. Which approach best supports this goal?
58 A chart truncates its y-axis to start at instead of , making a change look dramatic. In the context of ethical storytelling, this is best described as:
59 You must process a live video stream, detect motion, and log events to a dashboard. Which combination of Python tools maps most appropriately to each subtask?
60 A pipeline scrapes prices hourly, stores them, and predicts trends. To keep it maintainable and avoid re-scraping unchanged pages, which design choice is most sound?
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →