Docsity

WGU D278 SCRIPTING AND PROGRAMMING FOUNDATIONS STUDY GUIDE & OA EXAM PREP, Exams of Programming Methodologies

Partial preview of the text

Download WGU D278 SCRIPTING AND PROGRAMMING FOUNDATIONS STUDY GUIDE & OA EXAM PREP and more Exams Programming Methodologies in PDF only on Docsity!

WGU D278 Scripting and Programming Foundations - 200 Practice Questions with Rationales Comprehensive Review - Programming Fundamentals, Algorithms, Data Types, Control Structures, and OOP SECTION 1: PROGRAMMING BASICS & DATA TYPES (Questions 1-50) Question 1 What is the main purpose of programming? A) To write long lines of code B) To give instructions to a computer to solve a problem C) To store data only D) To replace databases Answer: B) To give instructions to a computer to solve a problem Rationale: Programming involves writing instructions that tell the computer how to perform specific tasks. Programs consist of instructions executed one at a time. Basic instructions include input (obtaining data), process (performing computations), and output (placing processed data somewhere). Question 2 In programming, what is an algorithm? A) A hardware device B) A list of random numbers C) A step-by-step set of instructions to solve a problem D) A data storage unit Rationale: Variable names cannot start with numbers or contain spaces or hyphens. Underscores are allowed. Variables refer to data (e.g., x, y, z) and their names reflect their varying values as the program assigns new data to them. Question 4 What is the correct symbol for single-line comments in many programming languages? A) // B) # C) D) /**/ Answer: B) # (in Python) Rationale: In Python, comments start with the # symbol. In other languages, // is used for single-line comments (C++, Java, JavaScript). Comments are used to document code and are ignored by the interpreter /compiler. Question 5 What does the equal sign (=) mean in programming? A) Comparison B) Assignment C) Addition D) Equality test Answer: B) Assignment Rationale: The equal sign (=) assigns a value to a variable. It does not compare values. Comparison uses == in most languages. For example, x = 5 assigns the value 5 to variable x. A) Integer B) String C) Float D) Boolean Answer: C) Float Rationale: A float (floating-point number) is used to represent decimal numbers, such as 1.75 meters. Integers are whole numbers, strings are text, and Booleans are True/False values. Variables that hold measurements often use float for precision. Question 8 What is a variable declaration? A) Assigning a value to a variable B) Declaring a new variable, specifying the variable's name and type C) Comparing two variables D) Removing a variable from memory Answer: B) Declaring a new variable, specifying the variable's name and type Rationale: A variable declaration introduces a new variable to the program, specifying its name and often its data type. In strongly typed languages like Java or C++, types must be declared before use. In dynamically typed languages like Python, the type is inferred at runtime. Question 9 Which type of language allows variables to be assigned without a specific type declaration? A) Static B) Dynamic Answer: B) 1.5 Rationale: When performing arithmetic with a float (2.0) and an integer (3), the integer is converted to a float, and a floating-point operation is performed. This is called implicit conversion. The result is 1.5. If both operands were integers, the result might be 1 in languages with integer division. Question 11 What is the result of 5 // 2 in Python? A) 2.5 B) 2 c)3 D) 2.0 Answer: B) 2 Rationale: In Python, the // operator performs integer (floor) division, giving only the whole number part of the quotient. 5 // 2 = 2. The % operator gives the remainder (5 % 2 = 1). Question 12 A variable should hold the number of seconds in a minute. This value is used in various calculations and never changes. How should the variable be declared? A) Variable integer secondsPerMinute B) Constant integer secondsPerMinute C) Variable float secondsPerMinute D) Constant float secondsPerMinute Answer: B) Constant integer secondsPerMinute Rationale: A constant holds a value that does not change during program execution. Since 60 seconds in a minute is a fixed value, Question 14 A variable should hold the names of all past U.S. presidents. Which data type should the variable be? A) Integer B) Float C) List or Array D) Boolean Answer: C) List or Array Rationale: A list (or array) is a data structure that stores multiple values in order. To store the names of all past presidents, a list of strings would be used. This allows the program to access each name by index and iterate through the collection. Question 15 What is the outcome of implicit conversion when assigning a float to an integer variable? A) The float is rounded to the nearest integer B) The fractional part is dropped C) The program throws an error D) The float is converted to a string Answer: B) The fractional part is dropped Rationale: When assigning a float to an integer variable, the right side's type is converted to match the left side's type. The fractional part is dropped (truncated), not rounded. For example, assigning 3.9 to an integer variable results in 3. Question 16 What is a string literal? Answer: B) Moves the cursor to the next output line Rationale: The newline character sequence (often \n) is a special two-character sequence that moves the cursor to the next output line invisibly. It is used to format output by creating line breaks. Question 18 Which of the following is NOT a basic instruction in a program? A) Input: Obtaining data from sources like files or keyboards B) Process: Performing computations on the data C) Output: Placing the processed data somewhere D) Compile: Translating the program to machine code Answer: D) Compile: Translating the program to machine code Rationale: Compilation is a separate step that occurs before program execution. The basic instructions within a program are input, process, and output. Variables hold data as the program executes. Question 19 A float variable is assigned the value 25. What is the actual value stored by the variable? A) 25 B) 25.0 C) 25.00 D) Error Answer: B) 25.0 Rationale: When assigning an integer to a float variable, the value is implicitly converted to a floating-point representation. Therefore, 25 becomes 25.0. This ensures the variable remains a float type. Question 21 Which operator is used to determine if a number is evenly divisible by 52 A) / B) % C) // D) * Answer: B) % Rationale: The modulo operator (Y%) returns the remainder of a division operation. If a number x is evenly divisible by 5, x % 5 will equal 0. For example, 10 % 5 == 0 is True. Question 22 What is the purpose of parentheses () in a programming expression? A) To indicate a comment B) To group expressions and control order of operations C) To define a variable D) To end a statement Answer: B) To group expressions and control order of operations Rationale: Parentheses are used to group expressions and explicitly control the order of operations. Operations within parentheses are evaluated first, following standard mathematical precedence rules. This helps avoid ambiguity in complex expressions. Question 23 Which of the following is a Boolean value? A) 1.0 B) True