Unit 6: Real-world applications - Practice Quiz

ECE181 — Introduction To Python 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 Which Python library is primarily used for computer vision and image processing tasks?

OpenCV-based image operations Easy
A. PyGame
B. Matplotlib
C. OpenCV
D. BeautifulSoup

2 Which function is used to read an image from a file in OpenCV?

OpenCV-based image operations Easy
A. cv2.showImage()
B. cv2.imread()
C. cv2.openImage()
D. cv2.loadFile()

3 In OpenCV, which color format are images loaded in by default?

OpenCV-based image operations Easy
A. CMYK
B. HSV
C. RGB
D. BGR

4 Which OpenCV function displays an image in a window?

OpenCV-based image operations Easy
A. cv2.view()
B. cv2.display()
C. cv2.imshow()
D. cv2.render()

5 PyGame is a Python library mainly used for creating what type of applications?

PyGame-based gaming creation Easy
A. Games and multimedia
B. Machine learning models
C. Database systems
D. Web servers

6 Which function must be called to start using PyGame's modules?

PyGame-based gaming creation Easy
A. pygame.init()
B. pygame.start()
C. pygame.run()
D. pygame.begin()

7 In PyGame, which object represents the main window or drawing surface?

PyGame-based gaming creation Easy
A. Surface
B. Frame
C. Panel
D. Canvas

8 Which PyGame concept is typically used to continuously update the game and handle events?

PyGame-based gaming creation Easy
A. Game loop
B. Render tree
C. Data pipeline
D. Event stack

9 Which Python library is commonly used to send HTTP requests to access a URL?

web-scraping-based url access Easy
A. requests
B. numpy
C. pygame
D. turtle

10 Which library is widely used to parse HTML content during web scraping?

web-scraping-based url access Easy
A. BeautifulSoup
B. Seaborn
C. PyGame
D. OpenCV

11 What does the term "web scraping" mean?

web-scraping-based url access Easy
A. Designing website layouts
B. Extracting data from websites automatically
C. Hosting websites on a server
D. Encrypting web traffic

12 An HTTP status code of 200 typically indicates what?

web-scraping-based url access Easy
A. The request succeeded
B. A server error occurred
C. The page was not found
D. Access is forbidden

13 Which Python library is one of the most widely used for creating basic plots and charts?

data visualization Easy
A. Matplotlib
B. OpenCV
C. PyGame
D. Requests

14 Which chart type is best suited for showing trends in data over time?

data visualization Easy
A. Word cloud
B. Scatter matrix
C. Line chart
D. Pie chart

15 Which library is built on top of Matplotlib and provides attractive statistical graphics?

data visualization Easy
A. Flask
B. BeautifulSoup
C. Seaborn
D. PyGame

16 Which chart is most appropriate for showing the proportion of parts to a whole?

data visualization Easy
A. Box plot
B. Pie chart
C. Histogram
D. Line chart

17 Which library is commonly used for numerical computing and working with arrays in Python?

discussion on advanced toolboxes in python Easy
A. Requests
B. NumPy
C. PyGame
D. Pillow

18 Which Python library is primarily used for data analysis and handling tabular data?

discussion on advanced toolboxes in python Easy
A. PyGame
B. Pandas
C. OpenCV
D. Turtle

19 Which of the following is a real-world application where Python is commonly used?

demonstration of real-world applications Easy
A. Data analysis and machine learning
B. Baking bread
C. Manufacturing car engines
D. Painting walls

20 In the context of data, what does "data storytelling" mainly involve?

storytelling Easy
A. Communicating insights using data and visuals
B. Deleting outdated records
C. Writing fictional novels with code
D. Encrypting datasets securely

21 In OpenCV, when you read an image using cv2.imread(), in what channel order are the pixel values stored by default?

OpenCV-based image operations Medium
A. RGB
B. BGR
C. HSV
D. Grayscale

22 You want to convert a color image img to grayscale in OpenCV. Which line accomplishes this?

OpenCV-based image operations Medium
A. gray = cv2.imread(img, 0)
B. gray = cv2.grayscale(img)
C. gray = cv2.convert(img, GRAY)
D. gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

23 What does the shape attribute img.shape return as (480, 640, 3) indicate about the image?

OpenCV-based image operations Medium
A. Width 480, height 640, and 3 color channels
B. 480 frames, 640 pixels, 3 bits
C. 480 rows, 640 channels, 3 layers
D. Height 480, width 640, and 3 color channels

24 In a typical PyGame program, which function must be called first to start up all imported PyGame modules?

PyGame-based gaming creation Medium
A. pygame.begin()
B. pygame.init()
C. pygame.run()
D. pygame.start()

25 Inside a PyGame main loop, which call is responsible for actually updating the full screen with everything drawn?

PyGame-based gaming creation Medium
A. pygame.event.get()
B. pygame.display.init()
C. pygame.screen.draw()
D. pygame.display.flip()

26 Why is pygame.time.Clock() combined with clock.tick(60) used in a game loop?

PyGame-based gaming creation Medium
A. To pause the game for 60 seconds
B. To count 60 total game events
C. To set the background refresh color
D. To limit the loop to a maximum of 60 frames per second

27 In PyGame, how do you typically detect that the user clicked the window's close button?

PyGame-based gaming creation Medium
A. Call pygame.display.quit() repeatedly
B. Wait for pygame.KEYDOWN
C. Check for event.type == pygame.QUIT in the event loop
D. Check pygame.window.closed()

28 When scraping a webpage in Python, which combination is most commonly used to fetch the HTML and then parse it?

web-scraping-based url access Medium
A. urllib to parse, requests to fetch
B. BeautifulSoup to fetch, requests to parse
C. json to fetch, csv to parse
D. requests to fetch, BeautifulSoup to parse

29 After response = requests.get(url), which attribute do you check to confirm the request succeeded (HTTP 200)?

web-scraping-based url access Medium
A. response.result
B. response.status_code
C. response.success
D. response.ok_flag

30 Using BeautifulSoup, which method returns a list of all <a> anchor tags on a page?

web-scraping-based url access Medium
A. soup.get('a')
B. soup.select_one('a')
C. soup.find_all('a')
D. soup.find('a')

31 A website's robots.txt disallows scraping certain paths. What is the correct interpretation for a responsible scraper?

web-scraping-based url access Medium
A. It signals which paths crawlers should not access, and should be respected
B. It is only relevant to search engines and can be ignored
C. It automatically blocks all Python requests
D. It encrypts the page so it cannot be parsed

32 In Matplotlib, which plot type is most appropriate for showing the relationship between two continuous numeric variables?

data visualization Medium
A. Scatter plot
B. Pie chart
C. Bar chart of categories
D. Histogram of one variable

33 You want to visualize the distribution and frequency of a single continuous variable such as exam scores. Which chart is best?

data visualization Medium
A. Pie chart
B. Histogram
C. Line chart
D. Scatter plot

34 In Matplotlib, what is the purpose of calling plt.show() at the end of a plotting script?

data visualization Medium
A. It clears all existing plots
B. It renders and displays the figure window
C. It saves the figure to disk
D. It sets the figure resolution

35 Which library is built on top of Matplotlib and provides high-level functions for attractive statistical graphics?

data visualization Medium
A. Pillow
B. Requests
C. Seaborn
D. NumPy

36 Which Python library is primarily used for numerical computing with efficient multi-dimensional array operations?

discussion on advanced toolboxes in python Medium
A. BeautifulSoup
B. Flask
C. NumPy
D. PyGame

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?

discussion on advanced toolboxes in python Medium
A. matplotlib Figure
B. requests Session
C. pandas DataFrame
D. numpy scalar

38 Which pair correctly matches a Python toolbox to its main purpose?

discussion on advanced toolboxes in python Medium
A. TensorFlow → web scraping
B. scikit-learn → machine learning
C. Pandas → 3D game rendering
D. Flask → image processing

39 A team builds a Python system that detects faces in a live camera feed. Which library is the natural core of this application?

demonstration of real-world applications Medium
A. Flask
B. OpenCV
C. Pandas
D. BeautifulSoup

40 A company wants to automatically collect daily product prices from several e-commerce sites into a spreadsheet for analysis. Which workflow best fits?

demonstration of real-world applications Medium
A. Read the images with OpenCV, then train scikit-learn
B. Render each site with PyGame, then plot with Seaborn
C. Scrape pages with requests/BeautifulSoup, then store in a pandas DataFrame
D. Fetch prices with Matplotlib, then save with NumPy

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?

OpenCV-based image operations Hard
A. Matplotlib requires normalization; divide the array by 255 before display
B. OpenCV loads images in BGR order while Matplotlib expects RGB; convert using cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
C. The image is corrupted; reload it with cv2.IMREAD_UNCHANGED
D. The image uses a wrong color depth; convert to grayscale first with 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:

OpenCV-based image operations Hard
A. Produces exactly the same result as a single box filter
B. Produces less smoothing than a single blur
C. Cannot be performed because kernels are not associative
D. Produces a smoothing effect similar to a blur but is not identical to a true box filter

43 When performing edge detection with cv2.Canny(img, threshold1, threshold2), what best describes the role of the two thresholds in hysteresis?

OpenCV-based image operations Hard
A. threshold1 sets Gaussian blur size and threshold2 sets the gradient magnitude
B. Pixels below threshold1 are strong edges; those above threshold2 are discarded as noise
C. Both thresholds must be exceeded simultaneously for a pixel to be an edge
D. Pixels above 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-based gaming creation Hard
A. Reduce the sprite's image resolution to slow rendering
B. Increase the fixed pixel step to compensate for the frame rate
C. Multiply movement by delta time (seconds since last frame) so motion is frame-rate independent
D. Call 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?

PyGame-based gaming creation Hard
A. The frame rate is capped too low with clock.tick(30)
B. Sprites are drawn before the screen is filled
C. The event queue is never processed with pygame.event.get() or pygame.event.pump()
D. The display was initialized with too small a resolution

46 For pixel-perfect collision between two moving sprites in PyGame, which approach is most accurate but computationally heavier than rectangle collision?

PyGame-based gaming creation Hard
A. Mask-based collision using pygame.mask.from_surface and mask.overlap
B. Comparing rect.colliderect on both sprites
C. Using pygame.sprite.spritecollide with collided=None
D. Checking Euclidean distance between sprite centers

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?

web-scraping-based url access Hard
A. The server returned a 200 status so the data must be present in a hidden attribute
B. The content is rendered client-side by JavaScript after page load, which requests does not execute
C. BeautifulSoup cannot parse <div> tags without the lxml parser
D. requests strips all dynamic tags from the response by default

48 Which statement about robots.txt and web scraping is most accurate?

web-scraping-based url access Hard
A. It encrypts URLs so scrapers cannot read the site structure
B. It automatically rate-limits any client that ignores it
C. It is an advisory standard that requests crawlers avoid certain paths, but it does not technically enforce access control
D. It is a firewall rule that blocks all unauthorized scraping requests

49 A scraper repeatedly hits a site and starts receiving HTTP 429 responses. Which combination best addresses this while remaining respectful?

web-scraping-based url access Hard
A. Disable SSL verification to bypass the rate limiter
B. Send requests faster to finish before the block takes effect
C. Switch every request to a new random User-Agent and ignore the status code
D. Add delays between requests and implement exponential backoff honoring the 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?

data visualization Hard
A. Increase the figure DPI to 300
B. Switch the plot color to a brighter palette
C. Add more gridlines to the linear axis
D. Use a logarithmic y-axis (e.g., plt.yscale('log'))

51 When designing a chart for viewers who may be color-blind, which practice is most effective?

data visualization Hard
A. Use only red and green to maximize contrast
B. Rely on a rainbow (jet) colormap for continuous data
C. Remove the legend so viewers focus on colors
D. Combine a color-blind-safe palette with redundant encodings like markers, line styles, or direct labels

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?

data visualization Hard
A. A violin plot or box plot showing the distribution shape per region
B. A single stacked bar of all regions combined
C. A pie chart of the same averages
D. A line chart connecting the regional means

53 In Matplotlib, what is the key difference between the stateful pyplot interface and the object-oriented (Axes) interface for complex multi-panel figures?

data visualization Hard
A. The OO interface cannot create subplots without plt.figure()
B. The OO interface gives explicit control over each Axes object, avoiding ambiguity about which subplot commands affect
C. The pyplot interface renders faster because it caches figures
D. Only the 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?

discussion on advanced toolboxes in python Hard
A. NumPy loops are automatically parallelized across all CPU cores by default
B. NumPy executes the operation in compiled C code over contiguous memory, avoiding per-element Python interpreter overhead
C. Python for loops cannot operate on numeric data
D. NumPy stores data on the GPU by default

55 A Pandas operation df[df['a'] > 0]['b'] = 5 produces a SettingWithCopyWarning and the change may not persist. What is the correct fix?

discussion on advanced toolboxes in python Hard
A. Use .loc for combined selection and assignment: df.loc[df['a'] > 0, 'b'] = 5
B. Convert the column to a list, modify it, and reassign
C. Wrap the expression in df.copy() before assigning
D. Disable the warning with 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?

discussion on advanced toolboxes in python Hard
A. Test data must never be numerically transformed
B. Fitting on all data leaks test-set statistics into training, producing overly optimistic evaluation
C. The scaler cannot process both sets simultaneously due to memory limits
D. Scaling the test set is impossible without the training labels

57 In data storytelling, a stakeholder audience needs to grasp one key takeaway quickly. Which approach best supports this goal?

storytelling Hard
A. Present every chart produced during analysis in chronological order
B. Lead with a clear headline insight and use annotations to direct attention to the supporting evidence
C. Maximize data density by overlaying all metrics on one axis
D. Remove all text so the numbers speak for themselves

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:

storytelling Hard
A. An error that Matplotlib prevents automatically
B. A misleading design choice that exaggerates differences and should be disclosed or avoided
C. A required convention for all bar charts
D. A best practice that improves resolution and is always appropriate

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?

demonstration of real-world applications Hard
A. Matplotlib for capture, OpenCV for logging, and Requests for the dashboard
B. Requests for capture, scikit-learn for logging, and PyGame for the dashboard
C. PyGame for capture, BeautifulSoup for motion detection, and NumPy for the dashboard
D. OpenCV for frame capture/motion detection, Pandas for event logging, and Matplotlib/Plotly for the dashboard

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?

demonstration of real-world applications Hard
A. Cache responses with conditional requests (ETag/If-Modified-Since) and separate scraping, storage, and modeling into modular stages
B. Combine scraping, storage, and modeling into one function for simplicity
C. Scrape every page fully each run regardless of changes to ensure freshness
D. Store all data only in memory to speed up predictions