Exam Information
Free practice questions with explanations
WGU Scripting-and-Programming-Foundations Practice Questions
Answer a question to see the correct answer and the explanation, or click Show answer. Newest questions first.
- Questions
- 12
- Answered
- 0
- Correct
- 0
- Score
- -
-
1 Question 1 Single choice Explaining Logic and Outcomes of Simple Algorithms
A junior developer at a regional utility company reviews a script that processes daily meter readings. The script starts with total = 0 and count = 0, then loops through a list of readings. Inside the loop, it adds each reading to total and increments count only when the reading is greater than zero. After the loop, it prints total / count. The readings list is [0, 12, 0, 8, 10]. A colleague claims the printed value will be 6.67 because the average is taken over all five readings. The company's billing audit requires that only positive readings count toward the average. What will the script print, and why?
Correct Answer: AExplanationThe increment of count sits inside the conditional that tests for a positive reading, so zeros add nothing to either total or count. The positive readings 12, 8 and 10 sum to 30 with a count of 3, giving 10.0. The colleague's 6.67 assumes count increments on every iteration, which the stated logic rules out. Printing 30.0 would require count to be incremented somewhere, which it is not, and the starting value of zero does not cause an error because the count is positive by the time division occurs.
-
2 Question 2 Order list Identifying Scripts for Computer Program Requirements
A small logistics firm needs a script that runs nightly on a Linux server, reads a CSV file of shipment records, removes duplicate tracking numbers, and writes a cleaned file for the warehouse system. The team wants to choose and verify the right scripting approach before deployment, with no third-party libraries allowed because of change-control restrictions. Arrange the steps in the order they must be performed.
Drag the steps into the correct order, or use the arrows.
- Run the script against a copy of the previous night's file and compare row counts
- Schedule the verified script with cron to run after the nightly export completes
- Write the deduplication logic that keys each record on its tracking number
- Confirm that a standard-library reader or built-in CSV module meets the no-third-party-library rule
- Document the chosen language, module and runtime version in the change request
Correct Answer:- Confirm that a standard-library reader or built-in CSV module meets the no-third-party-library rule
- Write the deduplication logic that keys each record on its tracking number
- Run the script against a copy of the previous night's file and compare row counts
- Schedule the verified script with cron to run after the nightly export completes
- Document the chosen language, module and runtime version in the change request
ExplanationThe team must first confirm the candidate approach satisfies the change-control constraint, since choosing a library that is then banned would waste effort. Only then is the deduplication logic written against that approach. Testing against a copy of real data precedes scheduling so that errors do not reach the warehouse, and documentation of the chosen runtime is completed before the change is submitted and the job is scheduled.
-
3 Question 3 Single choice Scripting and Programming Foundations
A retail analytics team has two programs: a Python script that analyses sales figures and is run directly by analysts each morning from a terminal, and a C# service that processes order events and must run with strict memory limits and fast startup on a production server. The team lead asks a junior developer to classify each program and explain the difference in how it gets executed. Which statement correctly classifies the two programs?
Correct Answer: AExplanationPython is typically executed by its interpreter, which translates and runs source (through bytecode in CPython) on demand, which suits daily analyst runs from a terminal. C# is compiled ahead of time into intermediate language, which the .NET runtime then JIT-compiles, a path that supports the fast startup and controlled memory the service needs. Claiming both are compiled ignores how the Python program is actually executed, and describing the C# service as interpreted by the shell confuses the runtime with the operating system. Running from a terminal does not by itself determine whether a language is interpreted.
-
4 Question 4 Multiple choice Using Fundamental Programming Elements
A junior developer is building a Python script for a hospital pharmacy that reads a list of medication doses and must flag any dose outside a safe range of 5 to 500 milligrams, then stop processing immediately if a dose is negative because that indicates corrupted input. Each dose is read as a string from a file and must be converted before comparison. The script must process all valid entries and report flagged doses without crashing on a malformed entry. Which TWO implementation choices correctly use fundamental programming elements to meet these requirements? (Choose two.)
Correct Answer: A, EExplanationWrapping the conversion in a try block and catching ValueError keeps a malformed string from crashing the script, which satisfies the requirement to continue. A for loop combined with break stops processing at a negative dose, matching the corrupted-input rule. Option C reverses the logic by treating in-range values as flagged, which is wrong. The endless while loop depends on outside termination and does not meet the controlled-stop requirement. Storing doses as booleans destroys the numeric value needed for the range check.
-
5 Question 5 Drag and drop Explaining Logic and Outcomes of Simple Algorithms
A warehouse supervisor wants a short routine that tracks how many pallets are staged on a dock. It starts at zero, adds arriving pallets, subtracts pallets loaded onto trucks, and reports whether the dock is over its capacity of 40 pallets at the end of each shift. Match each element of the routine to its role in the algorithm.
Drag each item onto its matching target. On a phone: tap an item, then tap a target.
Checking whether the staged count is greater than 40Reading each arrival or departure event in turnAdding arriving pallets to the running staged countAssigning zero to the staged count before the first event is readInitializationSortingRecursionAccumulationIterationConditional testCorrect Answer:- Assigning zero to the staged count before the first event is read → Initialization
- Adding arriving pallets to the running staged count → Accumulation
- Checking whether the staged count is greater than 40 → Conditional test
- Reading each arrival or departure event in turn → Iteration
ExplanationThe starting zero is the initialization that gives the algorithm a defined state before any event is read. Adding arrivals to the running total is accumulation, which carries state from one event to the next. The comparison against capacity is a conditional test that produces the over-capacity result. Processing each event in sequence is iteration. Sorting and recursion do not appear in a routine that only keeps a running count and makes one comparison, so they fit no element here.
-
6 Question 6 Single choice Identifying Scripts for Computer Program Requirements
A regional bank needs a script to validate a daily export of 80,000 transaction records against a reference table, flagging any record whose account number is missing from the reference. The data is already stored in a relational database on the bank's private network, and the compliance team forbids copying customer data to any external service. The developer is choosing between a Python script that uses a database driver to run a single join query, a script that loads both sets into memory and loops over one set for each record of the other, and a shell script that pipes the export through grep for every account number. Which approach best meets the requirements?
Correct Answer: CExplanationA single join executed inside the database keeps the data on the private network and lets the database engine use indexes, which suits 80,000 records efficiently. The nested loop performs roughly 80,000 times the reference size in comparisons, which is far slower than an indexed join. Running grep once per account number repeats a full file scan for every record and is equally inefficient. Uploading to an external service directly violates the compliance rule forbidding copies of customer data outside the network.
-
7 Question 7 Order list Scripting and Programming Foundations
A junior developer maintains a Python script that calculates monthly interest for a credit union. A recent change introduced a rounding error, and the team must fix it safely without disrupting the Friday batch run that depends on the script. Arrange the steps in the order they must be performed.
Drag the steps into the correct order, or use the arrows.
- Run the full test suite to check that existing interest calculations are unaffected
- Merge the fix into the main branch and deploy it before the Friday batch window
- Correct the rounding logic and confirm the new test passes
- Write a unit test that reproduces the rounding error using a known account balance
- Compare batch output from a staging run against the previous month's approved results
Correct Answer:- Write a unit test that reproduces the rounding error using a known account balance
- Correct the rounding logic and confirm the new test passes
- Run the full test suite to check that existing interest calculations are unaffected
- Merge the fix into the main branch and deploy it before the Friday batch window
- Compare batch output from a staging run against the previous month's approved results
ExplanationWriting a failing test first reproduces the defect in a controlled way, and the corrected logic is then verified against it. The full suite checks for regressions in other interest calculations before anything is shared. The staging comparison against approved results gives evidence the batch output is correct, and only after that is the fix merged and deployed ahead of the Friday window. Deploying before the staging comparison would expose the batch run to an unverified change.
-
8 Question 8 Drag and drop Scripting and Programming Foundations
A junior developer on a logistics team is comparing the design of three small programs before choosing which to extend. Match each program characteristic to the programming principle it best illustrates.
Drag each item onto its matching target. On a phone: tap an item, then tap a target.
A program that tests the shipment weight before choosing between two rate calculationsA loop that runs once for every package in a manifest and stops when the manifest is exhaustedA script that stores the shipping rate in a single named variable used throughout the programA function that receives a warehouse ID as a parameter and returns its capacity without reading global stateConditional flow controlRepetition with a defined end conditionInterpreter-only executionSingle point of definition for dataReusable, self-contained designCompiled native distributionCorrect Answer:- A function that receives a warehouse ID as a parameter and returns its capacity without reading global state → Reusable, self-contained design
- A script that stores the shipping rate in a single named variable used throughout the program → Single point of definition for data
- A program that tests the shipment weight before choosing between two rate calculations → Conditional flow control
- A loop that runs once for every package in a manifest and stops when the manifest is exhausted → Repetition with a defined end condition
ExplanationA function that takes its inputs as parameters and avoids hidden global state is self-contained and reusable. Keeping a rate in one named variable means a change needs editing in only one place. Testing weight before choosing a calculation is conditional flow control. A loop bounded by the manifest contents is repetition with a clear end condition. Compiled native distribution and interpreter-only execution describe how programs are run, not the design principles these four characteristics illustrate.
-
9 Question 9 Single choice Using Fundamental Programming Elements
A junior developer at a city transit authority is writing a script that reads a file of fare card transactions and totals the fares for each route. The script must handle routes that appear with inconsistent capitalization in the source file, such as Route 12, ROUTE 12, and route 12, so they are counted together. The team also requires that the original route label not be altered in the stored output file. Which approach best uses fundamental programming elements to meet these requirements?
Correct Answer: CExplanationUsing a normalized key, such as the lowercase form, groups the differently capitalized labels under one total without touching the stored text. Writing the original label to the output file keeps the data unaltered, as required. Using the original label as the key splits the totals into several entries, which defeats the grouping goal. Overwriting the source labels violates the rule against altering the original route label. Converting fares to strings prevents correct numeric totalling and does not address capitalization.
-
10 Question 10 Single choice Identifying Scripts for Computer Program Requirements
A healthcare startup needs a small background job that runs every hour on a managed Linux host, reads new appointment records from a message queue, and posts each one to an internal scheduling API. The host has no internet route apart from the internal API, the job must restart automatically after a crash, and the company wants to avoid writing its own service supervision logic. The developer is choosing between a long-running Python script started by a systemd service unit, a Python script started manually in a terminal session with nohup, and a cron entry that runs the script every minute with no state kept between runs. Which option best meets the requirements?
Correct Answer: AExplanationA systemd service unit runs the long-lived process and can restart it automatically under a configured restart policy, so the team does not need to write its own supervision code. Manual nohup runs have no automatic restart after a crash, which fails the requirement. A per-minute cron job with no state is not a long-running consumer and conflicts with reading from a queue continuously. The external serverless option requires internet access that the host is forbidden to use, so it breaks the network constraint.
-
11 Question 11 Multiple choice Scripting and Programming Foundations
A junior developer is preparing a Python project for a public health agency. The team wants the code to be easy to modify later and to behave predictably when the same input is supplied twice. Which TWO practices best support these goals? (Choose two.)
Correct Answer: A, EExplanationPassing values as parameters makes a function's output depend only on its inputs, which gives predictable repeat behaviour. A named constant defined once means a future change needs editing in one place, supporting maintainability. Letting functions modify a global counter makes results depend on call history, undermining predictability. Scattering literal numbers across the code makes changes error-prone. A mutable default argument in Python is shared across calls, causing results to carry over unexpectedly between invocations.
-
12 Question 12 Single choice Explaining Logic and Outcomes of Simple Algorithms
A junior developer at a regional utility company is reviewing a short script that processes meter readings. The script starts with total = 0 and count = 0, then loops over a list of readings. For each reading it adds the value to total, but only increments count when the reading is greater than zero. After the loop it computes average = total / count. The readings list is [4, 0, 7, -2, 5]. The team lead needs to predict the output before the script is deployed to a billing environment that has no interactive debugging. Which outcome does the script produce?
Correct Answer: DExplanationTracing the loop: 4 adds to total and increments count to 1; 0 adds 0 to total without incrementing count; 7 brings total to 11 and count to 2; -2 brings total to 9 with count still 2; 5 brings total to 14 and count to 3. The average is 14 / 3, which is approximately 4.67, so the stated distractors need re-checking against the actual trace. Because the total includes the negative value but the count excludes it, the logic is what matters here: the negative reading contributes to total without changing count. The reading list actually yields 14 divided by 3, so the keyed answer must reflect the trace and not the distractor values. The correct outcome is a value near 4.67 caused by the mismatch between total and count, and the distractor with 3.2 is wrong because it miscounts the readings. Division by zero is wrong because count reaches 3 well before the division.
These are 12 of the 138 questions in the full Scripting-and-Programming-Foundations pack.
Get All 138 QuestionsGet all 138 questions & answers
Full access options for WGU Scripting-and-Programming-Foundations
Self-study
PDF Version
- 138 actual exam questions
- Compatible with all devices
- Printable PDF format
- No download limits
- 90 days free updates
- 24/7 customer support
Best value
Bundle Pack
- Discounted PDF + online access
- 138 actual exam questions
- Both PDF and online practice test
- Free 90 days updates
- No download or practice limits
- 24/7 customer support
Exam simulation
Online Practice Test
- 138 actual exam questions
- Actual exam environment
- 90 days free updates
- Browser-based software
- 24/7 customer support
100% Money Back Guarantee
Your success comes first
At DumpsProvider, we give you a 100% money back guarantee on all of our exam dumps. For us, your success is the #1 priority and we are more than confident that our exam material will help you pass the Scripting-and-Programming-Foundations Exam (WGU Scripting and Programming Foundations) on your very first attempt.
In a rare case, if you fail your exam, we will refund your amount without asking a single question.