WGU Scripting and Programming Foundations (D278) Exam Questions

Page: 1 / 14
Total 138 questions
Question 1

Which characteristic specifically describes an object-oriented language?



Answer : D

Object-oriented programming (OOP) is characterized by the concept of encapsulating data and operations within objects. This characteristic is fundamental to OOP and distinguishes it from procedural programming, which is structured around functions rather than objects. In OOP, objects are instances of classes, which define the data (attributes) and the operations (methods) that can be performed on that data. This encapsulation of data and methods within objects allows for more modular, reusable, and maintainable code.

The characteristics of object-oriented programming languages are well-documented and include encapsulation, abstraction, inheritance, and polymorphism.These principles are foundational to OOP and are supported by languages like C++, Java, and Python12345.


Question 2

An algorithm should output "OK" if a number is between 98.3 and 98.9, else the output is "Not OK." Which test is a valid test of the algorithm?



Answer : B

Comprehensive and Detailed Explanation From Exact Extract:

A valid test checks if the algorithm produces the expected output for a given input, according to its specification. The algorithm outputs 'OK' for numbers in the range [98.3, 98.9] (inclusive or exclusive bounds not specified, but typically inclusive in such problems) and 'Not OK' otherwise. According to foundational programming principles, we evaluate each test case.

Specification:

Input in [98.3, 98.9] Output: 'OK'.

Input outside [98.3, 98.9] Output: 'Not OK'.

Option A: 'Input 98.6. Ensure output is 'Not OK.'' Incorrect. Since 98.6 is between 98.3 and 98.9 (98.3 98.6 98.9), the output should be 'OK', not 'Not OK'. This test is invalid.

Option B: 'Input 98.6. Ensure output is 'OK.'' Correct. 98.6 is within the range, and the expected output is 'OK', making this a valid test.

Option C: 'Input 99.9. Ensure output is 'OK.'' Incorrect. 99.9 is outside the range (99.9 > 98.9), so the output should be 'Not OK', not 'OK'. This test is invalid.

Option D: 'Input 99.9. Ensure output is '98.9.'' Incorrect. The algorithm outputs either 'OK' or 'Not OK', not a numerical value like '98.9'. This test is invalid.

Certiport Scripting and Programming Foundations Study Guide (Section on Algorithm Testing).

General Programming Principles: Testing and Validation.

W3Schools: ''Python Conditions'' (https://www.w3schools.com/python/python_conditions.asp).


Question 3

Which three statements describe a characteristic of a programming library?



Answer : A, B, D

A programming library is a collection of pre-written code that developers can use to optimize tasks and improve productivity. Here's why the selected statements are correct:

A: Libraries must be included or imported into your program before you can use the functions or objects they contain.This is because the program needs to know where to find the code it's executing12.

B: A library typically includes multiple functions, objects, or classes that are related to a specific task or area of functionality.This allows developers to reuse code efficiently12.

D: By providing pre-written code, libraries save developers time and effort, which in turn improves their productivity.Instead of writing code from scratch, developers can focus on the unique aspects of their project12.

The other options are incorrect because:

C: While it's true that poorly designed libraries can affect performance, well-designed libraries can actually make programs more efficient by providing optimized code.

E: A single program can include multiple libraries as needed. There's no limit to the number of libraries a program can use.

F: Libraries often contain multiple functions and variables, not just one function.


CareerFoundry's guide on what a programming library is1.

Codingem's complete guide on libraries in programming2.

Question 4

A program allows the user to play a game. At the end of each game, the program asks the user if they want to play again.

Which programming structure on its own is appropriate to accomplish this task?



Answer : C

The most appropriate programming structure to repeatedly ask a user if they want to play a game again is a while loop. This is because a while loop can execute a block of code as long as a specified condition is true. In this case, the condition would be whether the user wants to play again or not. The while loop will continue to prompt the user after each game and will only exit if the user indicates they do not want to play again. This makes it an ideal choice for tasks that require repeated execution based on user input.

For loops are generally used when the number of iterations is known beforehand, which is not the case here as we cannot predict how many times a user will want to play the game. Nested for loops and if-else statements are not suitable for repeating tasks based on dynamic user input.


Loops in Programming - GeeksforGeeks1

Use the right loop to repeat tasks - Learn programming with Java - OpenClassrooms2

Using For and While Loops for User Input in Python - Stack Abuse3

Question 5

What is a string?



Answer : C

In the context of programming, a string is traditionally understood as a sequence of characters. It can include letters, digits, symbols, and spaces, and is typically enclosed in quotation marks within the source code. For instance, ''Hello, World!'' is a string. Strings are used to store and manipulate text-based information, such as user input, messages, and textual data within a program. They are one of the fundamental data types in programming and are essential for building software that interacts with users or handles textual content.


Coderslang: Become a Software Engineer1

Wikipedia2

Programming Fundamentals3

TechTerms4

Question 6

What is one task that could be accomplish using a while loop?



Answer : B

A while loop is used to repeatedly execute a block of code as long as a specified condition is true. In the context of the given options:

Option A could use a simple if-else statement to compare two numbers and print the larger one.

Option B is a classic example of a use case for a while loop. The loop can run until the correct password is entered or the maximum number of attempts is reached.

Option C could be accomplished with a single if statement to check if the number is a multiple of 10.

Option D can also be done with an if-else statement to check the properties of the number.

Therefore, the task that is best suited for a while loop isOption B, where the user is asked to enter a password repeatedly until a correct password is entered or a certain number of incorrect attempts have been made. This requires the program to loop through the password prompt and check the conditions after each input, which is what while loops are designed for.


''Programming Foundations: Fundamentals'' by Simon Allardice, Lynda.com.

''Introduction to Computer Science and Programming Using Python,'' MITx on edX.

''Python Crash Course'' by Eric Matthes.

Question 7

Which type of language requires variables to be declared ahead of time and prohibits their types from changing while the program runs?



Answer : C

The type of language that requires variables to be declared ahead of time and prohibits their types from changing while the program runs is known as a statically typed language. In statically typed languages, the type of a variable is determined at compile-time and cannot be changed during runtime. This means that the compiler must know the exact data types of all variables used in the program, and these types must remain consistent throughout the execution of the program. Statically typed languages require developers to declare the type of each variable before using it, which can help catch type errors during the compilation process, potentially preventing runtime errors and bugs.


https://www.remotely.works/blog/understanding-the-differences-static-vs-dynamic-typing-in-programming-languages

Page:    1 / 14   
Total 138 questions