
2026 Latest Foundations-of-Computer-Science dumps Exam Material with 72 Questions
WGU Foundations-of-Computer-Science Questions and Answers Guarantee you Oass the Test Easily
NEW QUESTION # 20
m = 30
n = 30
What will be the output of print(id(m), id(n)) after executing the following code?
- A. Error
- B. Two identical numbers
- C. 0 0
- D. Two different numbers
Answer: B
Explanation:
In Python, id(x) returns the "identity" of an object, which in CPython (the most common implementation) is typically the object's memory address. When you write m = 30 and n = 30, both names may refer to thesame integer objectbecause CPython caches a range of small integer objects for efficiency. This optimization means that commonly used small integers are pre-created and reused, so repeated occurrences of the same small integer literal often point to the same object, producing identical id() values. As a result, print(id(m), id (n)) will most likely displaytwo identical numbersin standard CPython builds when 30 falls within the cached range. (Real Python) This behavior is an implementation detail, but it is widely discussed in Python education because it illustrates the difference between object identity (whether two variables reference the same object) and value equality (whether two objects have the same value). Even if id(m) and id(n) were different in some edge environment, m == n would still be True because the values are equal; id() is about identity, not value. The options "0 0" and "Error" are not consistent with how id() works for valid objects.
NEW QUESTION # 21
Which Python function would be used to check the data type of a variable bmi?
- A. datatype(bmi)
- B. type(bmi)
- C. check(bmi)
- D. typeof(bmi)
Answer: B
Explanation:
Python provides the built-in function `type()` to determine the data type (more precisely, the class) of an object. Because Python is dynamically typed, variable names are references to objects, and the object itself carries its type information at runtime. Calling `type(bmi)` returns a type object such as `<class 'int'>`, `<class
'float'>`, or `<class 'str'>` depending on what value is currently bound to the name `bmi`. This is the standard, textbook-approved method for checking an object's type in Python.
Option C, `typeof(bmi)`, is common in JavaScript, not Python. Options A and B are not standard Python built- ins; they might exist in user code or other languages, but not in Python's core language. In typical coursework and professional usage, `type()` is the correct function.
Textbooks also discuss how `type()` differs from `isinstance()`. While `type()` directly reports the object's class, `isinstance(bmi, float)` is often preferred when you want to allow subclass relationships. For example, in object-oriented programming, a subclass instance should often be treated as an instance of its parent class, which `isinstance` supports. However, when the question asks specifically for the function used to "check the data type," the expected answer is `type()`.
# Understanding type inspection helps with debugging, writing robust functions, and reasoning about operations that are valid for different data types.
NEW QUESTION # 22
Which is the most powerful command line interface on Windows systems?
- A. Control Panel
- B. Command Prompt
- C. Task Manager
- D. PowerShell
Answer: D
Explanation:
On Windows,PowerShellis generally regarded as the most powerful command-line environment because it is both a shell and a scripting language designed for system administration and automation. Traditional Command Promptfocuses on running console commands and batch files with plain-text input and output.
PowerShell, by contrast, uses an object-oriented pipeline: commands (calledcmdlets) output structured objects rather than raw text. This enables more reliable scripting and data manipulation, since you can filter, sort, and transform results without fragile text parsing.
Textbooks covering operating systems and administration emphasize automation and management at scale.
PowerShell integrates tightly with Windows management technologies, such as WMI/CIM, the registry, services, event logs, and Active Directory environments. It also supports remote management, scripting modules, robust error handling, and modern security features. This makes it particularly suitable for tasks like provisioning users, configuring machines, auditing systems, and orchestrating deployments.
The other options are not command-line interfaces in the same sense. Task Manager is a GUI tool for viewing processes and performance. Control Panel is also GUI-based for system configuration. Command Prompt is a command line interface, but it is less capable for complex administration compared to PowerShell's scripting and object pipeline.
Therefore, from a computer science and systems perspective, PowerShell is the most powerful Windows CLI environment among the choices.
NEW QUESTION # 23
What are Python functions that belong to specific Python objects?
- A. Methods
- B. Scripts
- C. Libraries
- D. Modules
Answer: A
Explanation:
In object-oriented programming, amethodis a function that is associated with an object (or its class) and is called using the dot operator. In Python, everything is an object, and many operations are provided through methods. For example, "hello".upper() calls the upper method of a str object, and [1, 2, 3].append(4) calls the append method of a list object. Textbooks emphasize that methods operate on an object's internal state and typically receive the object itself as an implicit first argument (commonly named self in class definitions).
This is what distinguishes methods from standalone functions.
Modules, scripts, and libraries are different organizational concepts. Amoduleis a file containing Python code, including function and class definitions. Ascriptis a Python program intended to be run directly. A libraryis a collection of modules that provides reusable functionality. None of these terms specifically mean
"functions that belong to objects."
Understanding methods matters because it connects to encapsulation and abstraction: objects provide behaviors (methods) that manipulate their data in well-defined ways. This design enables clearer APIs and supports polymorphism, where different object types can expose methods with the same name but different implementations. In Python, method calls are central to working with built-in types (strings, lists, dictionaries) and with user-defined classes, making "methods" the correct term for functions that belong to specific objects.
NEW QUESTION # 24
What is the purpose of user management and access control in a networked environment?
- A. To establish permissions and monitor resource usage
- B. To restrict all users from accessing confidential documents
- C. To ensure all users have the same level of access to resources
- D. To provide unlimited access to all network resources
Answer: A
Explanation:
In a networked environment, user management and access control exist to ensure that resources are used securely, appropriately, and accountably. The core idea isauthorization: defining what each user (or group of users) is allowed to do-read files, modify data, access applications, administer systems, and so on. This is commonly guided by the principle ofleast privilege, which states that users should receive only the permissions necessary to perform their tasks. Proper access control reduces the damage from mistakes and limits the impact of compromised accounts.
User management also includesauthenticationsupport (ensuring a user is who they claim to be) and administrative functions such as creating accounts, assigning roles, revoking access, and enforcing policies (password rules, multi-factor authentication requirements, session timeouts). In many systems, access control is implemented through models like discretionary access control (DAC), role-based access control (RBAC), or mandatory access control (MAC), each with different security properties.
Option B correctly reflects this: the goal is to establish permissions and to monitor or audit usage (logging access, tracking changes, detecting suspicious behavior). Option A is wrong because equal access is rarely secure or practical. Option C is the opposite of secure practice. Option D is too absolute:
systems typically restrict some users from some confidential resources, not all users from all confidential documents.
NEW QUESTION # 25
Which Windows 11 tool enables a user to manually add a Bluetooth device if it does not automatically configure when first connected?
- A. Task scheduler
- B. Network center
- C. Windows defender
- D. Device manager
Answer: D
Explanation:
When a Bluetooth device does not configure automatically, the underlying issue is often driver discovery, device enumeration, or the Bluetooth adapter's state. In Windows, the tool traditionally associated with manually managing hardware devices and their drivers isDevice Manager. It lets a user view hardware categories (including Bluetooth adapters), enable or disable devices, update drivers, uninstall and rescan, and address "unknown device" situations. These actions are core to manual configuration because they influence whether Windows can properly recognize and communicate with a Bluetooth device.
Windows 11 pairing itself is typically initiated from the Settings app under Bluetooth and devices, where a user chooses "Add device" to pair a new accessory. (Microsoft Support) However, among the options provided, only Device Manager is a hardware-configuration tool that can resolve situations where automatic configuration fails due to driver or adapter problems. Network-related tools do not handle local device drivers, Task Scheduler automates tasks rather than adding devices, and Windows Defender is focused on security and malware protection rather than device setup.
From a systems perspective, this reflects a key operating-systems concept: successful device use requires both discovery/pairing and a correctly installed driver stack. Device Manager is the standard interface for the driver and device side of that equation, which is why it is the best match to "manually add or configure" hardware in the given choices.
NEW QUESTION # 26
What code would print a subarray of the first 5 elements in numpy_array?
- A. print(numpy_array.get(0, 5))
- B. print(numpy_array[:5])
- C. print(numpy_array[1:5])
- D. print(numpy_array.get(5, 1))
Answer: B
Explanation:
NumPy arrays support slicing using the same start:stop convention as Python sequences. To take the first five elements, you want indices 0 through 4. The slice numpy_array[:5] means "start from the beginning (default start is 0) and stop before index 5." Because the stop index is exclusive, this returns exactly the first five elements. Printing that slice with print(numpy_array[:5]) displays a 1D view (or copy depending on context) containing those elements.
Option A, numpy_array[1:5], starts at index 1, so it returns elements 1 through 4-only four elements-and it excludes the element at index 0, so it is not the first five elements. Options B and D are incorrect because NumPy arrays do not provide a .get() method for slicing in this manner; .get() is a method associated with dictionaries, not arrays.
Textbooks stress slicing because it is efficient and expressive, especially in data analysis. With slicing, you can take prefixes, suffixes, windows, or regularly spaced samples without writing loops. In NumPy, slicing is particularly important because many slices create views into the same underlying data buffer, enabling memory-efficient operations on large datasets. Understanding inclusive start and exclusive stop boundaries is critical to avoid off-by-one mistakes and to work correctly with batches and segments of numerical data.
NEW QUESTION # 27
What is the time complexity of a quicksort algorithm?
- A. O(n)
- B. O(1)
- C. O(log n)
- D. O(n log n)
Answer: D
Explanation:
Quicksort is a divide-and-conquer sorting algorithm. It works by selecting a pivot element, partitioning the array into two subarrays (elements less than the pivot and elements greater than the pivot), and then recursively sorting those subarrays. In the average case, the partition step splits the array into roughly equal halves, so the recurrence is commonly written as (T(n) = T(n/2) + T(n/2) + O(n)), where (O(n)) is the cost of partitioning. This solves to (O(n \log n)), which is why quicksort is widely taught as an efficient general- purpose sorting method.
However, textbooks also emphasize that quicksort has a worst-case time complexity of (O(n^2)) when partitions are extremely unbalanced (for example, repeatedly choosing the smallest or largest element as the pivot on already sorted input). Practical implementations reduce the likelihood of worst-case behavior using randomized pivots or "median-of-three" pivot selection. Despite the worst-case, quicksort is often very fast in practice because it has good cache performance and low constant factors, and it sorts in place with only (O (\log n)) average recursion stack space.
Among the provided options, the correct expected complexity for quicksort (average-case, and commonly cited in coursework questions) is (O(n \log n)). The other options are too small to represent the cost of sorting arbitrary data.
NEW QUESTION # 28
Which order is impossible when traversing a binary tree using depth first search?
- A. Level-order traversal
- B. In-order traversal
- C. Pre-order traversal
- D. Post-order traversal
Answer: A
Explanation:
Depth-first search (DFS) explores a tree by going as deep as possible along a branch before backtracking. In binary trees, DFS gives rise to the classic traversal orderspre-order,in-order, andpost-order, each defined by when you "visit" the node relative to its left and right subtrees. Pre-order visits the node first, then left subtree, then right subtree. In-order visits left subtree, then the node, then right subtree. Post-order visits left subtree, then right subtree, then the node. These are all DFS-based because they fully explore subtrees before moving sideways to another branch.
Level-order traversalis different: it visits nodes layer by layer from the root outward (all nodes at depth 0, then depth 1, then depth 2, etc.). This is a hallmark ofbreadth-first search (BFS), not DFS. Textbooks emphasize this distinction because DFS and BFS have different properties: BFS naturally finds shortest paths in unweighted graphs and produces level-order traversal in trees, while DFS is useful for tasks like topological sorting, cycle detection, and exploring structure recursively.
Therefore, the traversal order that is impossible to produce as a depth-first traversal of a binary tree is level-order traversal. The DFS orders (pre-, in-, post-) are all achievable by depth-first strategies, typically implemented recursively or with an explicit stack.
NEW QUESTION # 29
print(20 # 5)
What will the output be of this line?
- A. no output
- B. Syntax Error
- C. #25
- D. 20 + 5
Answer: A
Explanation:
In Python, the # character begins acomment. Everything from # to the end of the line is ignored by the interpreter and is not executed. Therefore, the line # print(20 # 5) producesno outputbecause it is a comment, not an executable statement. This is a standard concept in programming language textbooks: comments are for humans, not for the machine, and they are used to document code, explain intent, temporarily disable statements during debugging, or leave notes about assumptions and design choices.
Even though the line contains an unusual symbol #, it does not matter here, because the interpreter never tries to parse the commented text. If the # were removed, then Python would attempt to parse print(20 # 5), and since # is not a valid Python operator, that would indeed trigger a syntax error. But with the leading #, the entire line is inert.
Option A is incorrect because nothing is evaluated. Option C is incorrect because comments are not printed; they remain only in the source code. Option D is incorrect for the commented version of the line, since Python does not check comment contents for syntax. Thus, the correct result is no output.
NEW QUESTION # 30
What is the output of print(employees[3]) when employees = ["Anika", "Omar", "Li", "Alex"]?
- A. "Omar"
- B. "Anika"
- C. "Li"
- D. "Alex"
Answer: D
Explanation:
Python lists are ordered sequences indexed starting from 0. This zero-based indexing is standard in many programming languages and is a core concept in data structures. For the list `employees = ["Anika", "Omar",
"Li", "Alex"]`, the mapping of indices to elements is: index 0 # "Anika", index 1 # "Omar", index 2 # "Li", index 3 # "Alex". Therefore, the expression `employees[3]` selects the element at index 3, which is `"Alex"`, and `print(employees[3])` outputs `Alex` (strings print without quotes in normal output).
Option A would be correct for `employees[1]`, option D would be correct for `employees[2]`, and option C would be correct for `employees[0]`. This kind of question tests understanding of list indexing, which is essential for iteration, slicing, and algorithm implementation.
# Textbooks also note the difference between indexing and slicing: indexing returns a single element, while slicing returns a sublist. Here, because square brackets contain a single integer index, it is indexing. If you attempted an index that is out of range, Python would raise an `IndexError`, which reinforces careful reasoning about list length and positions. Understanding these fundamentals is critical for correctly manipulating datasets, where row/column positions and offsets frequently matter.
NEW QUESTION # 31
The np_2d array stores information about multiple family members. Each row represents a different person, and the columns store family member attributes in the following order:
Age (years)
Weight (pounds)
Height (inches)
How is the weight of all family members selected from the np_2d array?
- A. np_2d[1, :]
- B. np_2d[2, :]
- C. np_2d[:, 1]
- D. np_2d[:, 2]
Answer: C
Explanation:
In a 2D NumPy array, rows and columns represent different dimensions of the data. The indexing form array
[row_selection, column_selection] allows you to select entire rows, entire columns, or submatrices. The slice :
means "all indices along this dimension." Since each row corresponds to a family member (a person), selecting weights forallfamily members means selectingall rowsfor the weight column.
The problem states the columns are ordered as: Age (column 0), Weight (column 1), Height (column 2).
Therefore, the weight column has index 1. The expression np_2d[:, 1] uses : to take every row and 1 to take the second column, producing a 1D array (or a column view) containing the weight values for all people.
Option A, np_2d[:, 2], would select the height column, not weight. Option C, np_2d[2, :], selects the third row (the third person) and all columns-age, weight, and height for just that one person. Option D, np_2d[1, :], selects the second person's entire row.
This column selection technique is fundamental in data analysis because datasets are often stored as
"rows = observations, columns = features," and extracting a feature vector is a frequent operation before computing statistics or building models.
NEW QUESTION # 32
What is the correct way to represent a boolean value in Python?
- A. "True"
- B. "true"
- C. true
- D. True
Answer: D
Explanation:
Python has a built-in boolean type named bool, which has exactly two values: True and False. These are language keywords/constants and are case-sensitive. Therefore, the correct representation of a boolean value is True (capital T, lowercase rest) or False (capital F). This is consistently taught in introductory programming textbooks because it affects conditional statements (if, while), logical operations (and, or, not), and comparisons.
Option A, "True", is a string literal, not a boolean. While it visually resembles the boolean constant, it behaves differently: non-empty strings are "truthy" in conditions, but "True" == True is false because they are different types (str vs bool). Option B, "true", is also a string, and it differs in casing as well. Option D, true, is not valid in Python; it will raise a NameError unless a variable named true has been defined.
Textbooks also stress that boolean values often result from comparisons, such as x > 0, and that booleans are a subtype of integers in Python (True behaves like 1 and False like 0 in arithmetic contexts). Still, their primary use is representing logical truth values for control flow and decision- making.
NEW QUESTION # 33
Which type of data structure is the only focus of a binary search?
- A. Ordered list
- B. Linked list
- C. Queue
- D. Stack
Answer: A
Explanation:
Binary search is designed for searching in asorted (ordered) sequence. Its efficiency comes from repeatedly comparing the target to the middle element and discarding half of the remaining search space. This halving logic only works when the data is ordered, because the algorithm relies on the guarantee that all elements on one side of the midpoint are smaller (or larger) than the midpoint. In textbooks, this requirement is stated explicitly: binary search assumes the collection is sorted according to the same ordering used for comparisons.
An "ordered list" is therefore the correct focus among the options. Binary search can be implemented on arrays or other random-access structures where you can quickly access the middle element by index. While you can conceptually perform binary search on a linked list, it becomes inefficient because finding the middle requires linear traversal, losing the O(log n) advantage. Stacks and queues are not appropriate because they restrict access to ends only (LIFO for stacks, FIFO for queues), preventing direct access to the midpoint and making the binary search strategy infeasible.
Thus, the central requirement for binary search is a sorted/ordered sequence, typically supporting efficient indexing, which is why the correct choice is an ordered list.
NEW QUESTION # 34
Which file system is commonly used in Windows and supports file permissions?
- A. FAT32
- B. HFS+
- C. NTFS
- D. EXT4
Answer: C
Explanation:
Windows commonly uses the NTFS (New Technology File System) for internal drives and many external drives because it supports advanced features required for modern operating systems. One of the most important features is support forfile and folder permissionsvia Access Control Lists (ACLs). Permissions enable the OS to enforce security policies by controlling which users and groups can read, write, execute, modify, or delete specific resources. This is fundamental to multi-user security and is a standard topic in operating systems and security textbooks.
FAT32 is an older file system designed for simplicity and broad compatibility. It does not provide the same fine-grained permission model as NTFS, which is why it is often used for removable media where cross- platform compatibility matters more than access control. HFS+ is historically associated with Apple's macOS systems, and EXT4 is widely used on Linux. While these file systems have their own permission and feature models, they are not the common Windows default for permission-managed storage in typical Windows deployments.
NTFS also supports journaling (improving reliability after crashes), large file sizes, quotas, compression, and encryption features (through Windows facilities). In enterprise environments, NTFS permissions integrate with Windows authentication and directory services, enabling centralized user management. Therefore, for Windows systems requiring file permissions, NTFS is the correct answer.
NEW QUESTION # 35
What is a correct call to the linear search defined as def linear_search(customersList, search_value): ?
- A. print(linear_search(customersList, search_value))
- B. find_linear(customersList)
- C. linear_search()(customersList)
- D. search_linear(customersList, search_value)
Answer: A
Explanation:
A function definition in Python specifies a function name and a list of parameters. Here, def linear_search (customersList, search_value): defines a function named linear_search that requirestwo argumentswhen called: a list (or sequence) of customer items and the value being searched for. A correct call must therefore supply both arguments in the same order: linear_search(customersList, search_value). Option B is correct because it calls the function properly and then prints the returned result.
Textbooks describe linear search as scanning the list from the beginning to the end, comparing each element to search_value until a match is found or the list ends. The function typically returns an index (e.g., position of the match) or a Boolean, or possibly -1/None if not found. Wrapping the call in print(...) is a standard way to display the returned value for testing or demonstration.
Option A is incorrect because it calls a different function name, not linear_search. Option C is incorrect because linear_search() would attempt to call the function with zero arguments, which would raise a TypeError, and then it tries to call the result as if it were another function. Option D uses a different function name (search_linear) and also contains a spelling mismatch compared to the given definition.
NEW QUESTION # 36
How can a user subset a NumPy array bmi to only include values over 23?
- A. bmi.get_values(>23)
- B. bmi.select(23)
- C. bmi[bmi > 23]
- D. bmi.where(bmi > 23)
Answer: C
Explanation:
NumPy supports a powerful technique calledBoolean indexing(also called Boolean masking) to filter arrays based on a condition. When you write bmi > 23, NumPy performs an element-wise comparison and produces a Boolean array of the same shape, containing True where the condition holds and False otherwise. Using that Boolean array inside square brackets, as in bmi[bmi > 23], tells NumPy to return a new 1D array containing only the elements whose mask value is True. This approach is heavily emphasized in scientific computing curricula because it expresses selection logic without explicit loops and runs efficiently in optimized compiled code.
Option B looks close but is not standard NumPy usage. The function commonly used is np.where(condition) or np.where(condition, x, y). While np.where(bmi > 23) can return indices, bmi.where(...) is not a NumPy array method; it is more associated with pandas objects. Options A and C are not valid NumPy APIs for filtering.
Boolean indexing is central in data analysis tasks such as removing invalid measurements, selecting a population subgroup, applying thresholds, and building feature subsets. It composes cleanly with vectorized computation, for example bmi[bmi > 23].mean(), enabling concise and high-performance numerical workflows.
NEW QUESTION # 37
What happens if you try to create a NumPy array with different types?
- A. The array will be created with no issues.
- B. The array will contain a single type, converting all elements to that type.
- C. The array will be split into multiple arrays, one for each type.
- D. The array will be created, but calculations will not be possible.
Answer: B
Explanation:
When NumPy constructs an ndarray, it chooses a single data type called the dtype for the entire array. This is a defining feature of NumPy arrays: unlike Python lists, which can hold mixed object types freely, a NumPy array is designed for efficient numerical computation by storing values in a uniform, contiguous representation. Therefore, if you provide mixed types at creation time, NumPy will select a dtype that can represent all provided values and will convert elements as needed.
This process is commonly described as type promotion or coercion to a common type. For example, mixing integers and floats produces a float array because floats can represent integers without loss of generality.
Mixing numbers and strings often results in a string dtype (or, in some cases, an object dtype), because numbers can be converted to their string representations. Once the dtype is chosen, the array behaves consistently under vectorized operations appropriate for that dtype.
Option B correctly summarizes this textbook behavior: the array will contain a single type, converting all elements to that type. Option A is too absolute-many mixed-type arrays still support calculations depending on the resulting dtype. Option C is vague and misses the crucial fact that conversion occurs. Option D is not how NumPy works; it never automatically splits inputs into multiple arrays by type.
Understanding dtype coercion matters because it affects memory usage, performance, and whether numerical operations behave as expected.
NEW QUESTION # 38
Which character is used to indicate a range of values to be sliced into a new list?
- A. ","
- B. "="
- C. ":"
- D. "+"
Answer: C
Explanation:
In Python, slicing is the standard mechanism for extracting arangeof elements from a sequence type such as a list, string, or tuple. The character that signals a slice range is thecolon:. The general slice syntax is sequence
[start:stop:step]. Most commonly, you see sequence[start:stop], where start is the index to begin from (inclusive) and stop is the index to end at (exclusive). This "inclusive start, exclusive stop" rule is emphasized in textbooks because it makes slice lengths easy to reason about: when step is 1, the number of elements returned is stop - start.
For example, if items = ["a", "b", "c", "d", "e"], then items[1:4] returns ["b", "c", "d"]. Omitting start defaults to the beginning (items[:3] gives the first three elements), and omitting stop defaults to the end (items[2:] gives everything from index 2 onward). The optional step supports patterns like items[::2] for every other element, and negative steps can reverse a sequence (items[::-1]).
The other characters do not define ranges in Python slicing: , separates items (or indices in multidimensional structures), + is addition/concatenation, and = is assignment. The colon is the slicing operator that indicates a range.
NEW QUESTION # 39
What statistical measure can be used to detect outliers in a dataset using NumPy?
- A. Mode
- B. Median absolute deviation
- C. Standard deviation
- D. Variance
Answer: B
Explanation:
Outlier detection often relies on measuring how far values deviate from a "typical" center. While variance and standard deviation can be used in simple z-score based methods, they arenot robust: a few extreme outliers can inflate the mean and standard deviation, masking the very outliers you want to find. A widely taught robust alternative is themedian absolute deviation (MAD), which is based on the median rather than the mean and therefore resists distortion by extreme values.
MAD is computed by first taking the median of the data, then computing the absolute deviation of each point from that median, and finally taking the median of those deviations. Because medians are stable under extreme values, MAD provides a strong baseline for identifying unusually distant points. Many textbooks and data analysis references present MAD as a robust scale estimator for outlier detection, often combined with a threshold rule such as flagging points whose deviation exceeds a constant multiple of MAD (with a scaling factor sometimes used to make it comparable to standard deviation under normality assumptions).
In NumPy, you can implement MAD using np.median() and np.abs(). Mode is generally not useful for continuous numeric outlier detection, and variance/standard deviation are more sensitive to outliers than MAD. Thus, among the given options, the best statistical measure for detecting outliers robustly is the median absolute deviation.
NEW QUESTION # 40
Which method converts the default smallest-to-largest index order of a list to instead be the opposite?
- A. flip()
- B. invert()
- C. reverse()
- D. sortDescending()
Answer: C
Explanation:
Python lists maintain an order, and sometimes you need to reverse that order so the last element becomes first and the first becomes last. The standard list method for reversing the elementsin placeis reverse(). For example, if nums = [1, 2, 3, 4], then nums.reverse() mutates the list so it becomes [4, 3, 2, 1]. This is a built-in operation taught in introductory programming texts because it is efficient and conceptually simple: it does not create a new list unless you explicitly copy the data.
It is important to distinguish reversing from sorting. Reversing changes the sequence order as-is, while sorting rearranges elements according to comparisons. The question refers to converting the index order to the opposite, which is reversing. If you wanted descendingsortedorder, you would typically use sort (reverse=True) or sorted(nums, reverse=True). But the direct method that reverses the list's order is reverse().
The other options are not standard Python list methods. sortDescending(), flip(), and invert() are not part of Python's built-in list API. Textbooks emphasize learning the correct method names because Python's standard library provides a consistent, widely used interface across programs. Thus, reverse() is the correct answer for reversing the index order of a list.
NEW QUESTION # 41
What is the correct way to convert an integer to a string in Python?
- A. int_to_str(variable)
- B. string(variable)
- C. str(variable)
- D. tostring(variable)
Answer: C
Explanation:
Python provides built-in type conversion functions that construct a value of a target type from a supplied object when possible. To convert an integer to a string, Python uses the constructor function str(). For example, str(42) produces the string "42". This operation is fundamental in programming textbooks because it enables tasks like formatting output, concatenating numbers into messages, building file names, or preparing numeric values for text-based storage and transmission.
Python distinguishes clearly between numeric types (int, float) and text type (str). You cannot concatenate an integer directly with a string (e.g., "Age: " + 30 raises a TypeError) because the types are different. Using str (30) resolves this by converting the integer into its string representation: "Age: " + str(30) becomes valid.
Modern Python commonly uses f-strings (f"Age: {30}"), which perform conversion automatically, but str() remains the canonical and explicit method.
Options A, B, and C are not standard Python built-ins for conversion. While some libraries define helper functions with similar names, the language's standard approach is str(...). Textbooks also highlight that str() is not limited to integers: it can convert many objects into readable string representations, often by invoking the object's __str__ method. This ties conversion to Python's object model and supports consistent display and logging across programs.
NEW QUESTION # 42
What is the expected output of numpy_array[1]?
- A. An error message in the array
- B. A display of the entire array
- C. The first element of the array
- D. The second element of the array
Answer: D
Explanation:
In Python and NumPy, indexing iszero-based, meaning the first element of a 1D sequence is at index 0, the second element is at index 1, and so on. A NumPy array behaves like a sequence for basic indexing, so numpy_array[1] returns the element stored at position 1 in the array. This is a fundamental concept taught in introductory programming and scientific computing: indexing selects a single element, while slicing selects a range.
For example, if numpy_array = np.array([5, 8, 13]), then numpy_array[0] is 5, numpy_array[1] is 8, and numpy_array[2] is 13. The expression numpy_array[1] therefore evaluates to thesecond element(8 in this example). This does not display the entire array (that would happen with print(numpy_array)), and it does not produce an error unless the array is too short. An error such as IndexError occurs only if index 1 is out of bounds, for example when the array has length 1 and you try to access numpy_array[1].
Textbooks emphasize careful reasoning about indices because off-by-one errors are common. In data analysis, correct indexing is crucial for extracting the right observations, features, or time steps from numerical datasets.
NEW QUESTION # 43
What is the slicing outcome of client_locations[1:3] from client_locations = ["TX", "AZ", "UT", "NY"]?
- A. ["TX", "UT"]
- B. ["TX", "AZ"]
- C. ["UT", "NY"]
- D. ["AZ", "UT"]
Answer: D
Explanation:
Python list slicing uses the notation list[start:stop], where start is inclusive and stop is exclusive. This means the slice begins at index start and includes elements up to, but not including, index stop. Lists in Python are zero-indexed, so for client_locations = ["TX", "AZ", "UT", "NY"], the indices are: 0 # "TX", 1 # "AZ", 2 #
"UT", 3 # "NY".
The slice client_locations[1:3] starts at index 1 and stops before index 3. Therefore, it includes elements at indices 1 and 2, which are "AZ" and "UT". The result is ["AZ", "UT"].
This slice rule is heavily emphasized in programming textbooks because it supports efficient sub-list extraction and is consistent across Python sequence types such as strings and tuples. It also helps avoid off-by-one errors by using an exclusive end boundary. The exclusive stop index makes it easy to take
"the first n items" via [0:n] and to split sequences at a boundary without overlap. In practical software development, slicing is widely used for batching data, windowing in algorithms, and parsing structured inputs, making it an essential Python skill.
NEW QUESTION # 44
......
Share Latest Foundations-of-Computer-Science DUMP Questions and Answers: https://www.pass4leader.com/WGU/Foundations-of-Computer-Science-exam.html
PDF Dumps 2026 Exam Questions with Practice Test: https://drive.google.com/open?id=12EbzS9SZHyZliv6fYNGGC4pHtq69LTU7