OA Exams

  • California, TX 70240
  • Info@gmail.com
  • Office Hours: 8:00 AM – 7:45 PM
  • web.groovymark@gmail.com
  • December 8, 2024

Question 01

Which Python function is used to add data to a file?

a) write()
b) read()
c) append()
d) load()

Correct Answer: a) write()

Explanation: The write() function is used to add data to a file in Python. The read() function is for reading files, append() adds to the end, and load() is for loading content in some specific formats.

Question 02

Which of the following creates a default greeting function in Python?

a) def greet(name, greeting = “Hello”):
b) def greet(name, greeting = “Hi”):
c) def greet(name, greeting = “Welcome to WGU”):
d) def greet(name, greeting = “Good Morning”)

Correct Answer: c) def greet(name, greeting = "Welcome to WGU")

Explanation: The code defines a Python function with a default greeting parameter of "Welcome to WGU".

Question 03

How do you resolve the syntax error in this Python function?

def multiply_numbers(num1, num2)  

    result = num1 * num2  

    return result  

a) Add parentheses around the return statement
b) Add a colon after the function definition
c) Remove the return statement
d) Add an equal sign

Correct Answer: b) Add a colon after the function definition

Explanation: A colon : is required after the function definition for proper syntax.

Question 04

Which Python data structure is used to store the following?

devices = [“router01”, “switch01”, “modem01”, “gateway01”, “printer01”]

a) Dictionary
b) Set
c) List
d) Tuple

Correct Answer: c) List

Explanation: The devices variable is storing a collection of strings in a list, which is an ordered and mutable sequence in Python.

Question 05

What does this Python code snippet do?

value = input(“Enter a number: “)  

result = int(value) + 10  

print(result)

a) Adds 10 to the value
b) Converts the input to a float
c) Subtracts 10 from the value
d) Multiplies the value by 10

Correct Answer: a) Adds 10 to the value

Explanation: The code converts the user's input into an integer and then adds 10 to it.

Question 06

How would you fix this error in the given Python code?

def check_processing_speed(current_speed, threshold_speed):  

    is_fast_processing = current_speed > threshold_speed  

    if is_fast_processing:  

        print(f”The processing speed of {current_speed} GHz is fast.”)  

    else:  

    print(f”The processing speed of {current_speed} GHz is not fast enough. Consider an upgrade.”)  

a) Increase the indentation of the print statement inside the else block
b) Decrease the indentation of the if statement
c) Remove the f-string from the print statements
d) Add parentheses around the print statements

Correct Answer: a) Increase the indentation of the print statement inside the else block

Explanation: The else block should be indented correctly to align with Python's indentation rules.

Question 07

Which data structure is best suited for storing immutable network interface records?

a) List
b) Set
c) Dictionary
d) Tuple

Correct Answer: d) Tuple

Explanation: A tuple is an immutable sequence type in Python, making it ideal for storing records that should not be changed.

Question 08

What is the index of the element 40 in the list?

numbers = [10, 20, 30, 40]

a) 0
b) 1
c) 2
d) 3

Correct Answer: d) 3

Explanation: In Python, the list index starts at 0, so 40 is at index 3.

Question 09

What are the characteristics of tuples in Python?

a) Ordered and mutable
b) Unordered and unchangeable
c) Ordered and unchangeable
d) Unordered and mutable

Correct Answer: c) Ordered and unchangeable

Explanation: Tuples in Python are ordered collections of items and are immutable (unchangeable).

Question 10

What is the error in the following Python code?

port = input(“Secure Web access? Y/N: “)  

if port == “Y”  

    print(“Use port 443.”)  

else  

    print(“Use port 80.”)

a) Missing parentheses in the print statements
b) Missing colons at the end of if and else lines
c) Incorrect variable name
d) Indentation error

Correct Answer: b) Missing colons at the end of if and else lines

Explanation: Colons are required after the if and else statements.

Question 11

What will be the result of this Python expression?

result = 5 + 3 * 2

a) 10
b) 16
c) 11
d) 8

Correct Answer: c) 11

Explanation: According to the order of operations, multiplication is done before addition, so 3 * 2 = 6, and then 5 + 6 = 11.

Question 12

What is the purpose of the is operator in Python?

a) To compare the values of two objects
b) To check if two variables refer to the same object in memory
c) To compare the types of two objects
d) To assign a value to a variable

Correct Answer: b) To check if two variables refer to the same object in memory

Explanation: The is operator checks if two variables point to the same object, not if their values are equal.

Question 13

What is the result of this Python expression?

bool(0)

a) True
b) False
c) 0
d) None

Correct Answer: b) False

Explanation: In Python, 0 is considered False, while any non-zero number is considered True.

Question 14

Which method is used to return the number of elements in a list?

a) size()
b) length()
c) len()
d) count()

Correct Answer: c) len()

Explanation: The len() function is used to return the number of elements in a list or any iterable object.

Question 15

Which of the following is used to declare a function in Python?

a) func
b) function
c) def
d) declare

Correct Answer: c) def

Explanation: The def keyword is used to define a function in Python.

Question 16

What is the output of the following code?

print(3 ** 2)

a) 5
b) 6
c) 9
d) 8

Correct Answer: c) 9

Explanation: The ** operator is used for exponentiation in Python, so 3 ** 2 is 3 raised to the power of 2, which equals 9.

Question 17

How can you convert the string “123” into an integer in Python?

a) str(123)
b) int(“123”)
c) float(“123”)
d) list(“123”)

Correct Answer: b) int("123")

Explanation: The int() function converts a string or float into an integer, provided that the string represents a valid integer.

Question 18

What is the default value of the step parameter in Python’s string slicing?

a) 0
b) 1
c) -1
d) 2

Correct Answer: b) 1

Explanation: The step parameter in Python slicing defaults to 1, meaning that the slicing proceeds through the string one character at a time.

Question 19

Which of the following methods removes whitespaces from the beginning and the end of a string in Python?

a) strip()
b) trim()
c) remove()
d) rstrip()

Correct Answer: a) strip()

Explanation: The strip() method removes leading and trailing whitespaces from a string

Question 20

What will be the result of this Python code?

fruits = [‘apple’, ‘banana’, ‘cherry’]

print(fruits[-1])

a) apple
b) banana
c) cherry
d) IndexError

Correct Answer: c) cherry

Explanation: Negative indexing in Python starts from the end of the list. So -1 refers to the last element, which is "cherry".

Complete the Captcha to view next question set.

Tags

Prev Post
WGU D102 Practice Exam Questions – Set 5 – Part 3
Next Post
WGU D522 Practice Exam Questions – Set 1 – Part 2