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 can be used to return the absolute value of a number?

a) abs()
b) round()
c) int()
d) float()

Correct Answer: a) abs()

Explanation: The abs() function returns the absolute value of a number. It removes any negative sign, leaving only the magnitude of the number.

Question 02

What will be the result of the following code snippet?

x = 10

y = 5

print(x // y)

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

Correct Answer: b) 2

Explanation: The // operator performs floor division, meaning it divides the numbers and rounds down to the nearest whole number. 10 // 5 results in 2.

Question 03

What is the output of the following Python code?

print(“Hello”[1])

a) H
b) e
c) l
d) o

Correct Answer: b) e

Explanation: Strings in Python are zero-indexed, meaning the first character is at index 0. So "Hello"[1] accesses the second character, which is 'e'.

Question 04

What will be the output of this code?

print(2 ** 3)

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

Correct Answer: b) 8

Explanation: The ** operator is used for exponentiation. 2 ** 3 means 2 raised to the power of 3, which equals 8.

Question 05

Which Python function is used to read input from the user?

a) input()
b) read()
c) scan()
d) get()

Correct Answer: a) input()

Explanation: The input() function reads a line of text entered by the user and returns it as a string.

Question 06

What is the result of this expression?

result = “Python” + “3”

print(result)

a) Python
b) Python3
c) 6
d) Error

Correct Answer: b) Python3

Explanation: The + operator concatenates strings. "Python" + "3" results in the string 'Python3'.

Question 07

What does the following Python code return?

len([1, 2, 3, 4, 5])

a) 4
b) 5
c) 6
d) 3

Correct Answer: b) 5

Explanation: The len() function returns the number of elements in a list. [1, 2, 3, 4, 5] contains 5 elements, so the result is 5.

Question 08

What does the following code return?

name = “Alice”

print(name.upper())

a) ALICE
b) alice
c) A
d) Error

Correct Answer: a) ALICE

Explanation: The upper() method converts all lowercase characters in a string to uppercase. 'Alice' becomes 'ALICE'.

Question 09

What does this code do?

numbers = [1, 2, 3]

numbers.append(4)

print(numbers)

a) [1, 2, 3]
b) [1, 2, 3, 4]
c) [1, 2, 4]
d) Error

Correct Answer: b) [1, 2, 3, 4]

Explanation: The append() method adds an item to the end of a list. In this case, the number 4 is added to the list [1, 2, 3].

Question 10

What will be the result of this Python code?

x = 5

y = 10

x, y = y, x

print(x, y)

a) 5 10
b) 10 5
c) 0 0
d) Error

Correct Answer: b) 10 5

Explanation: The code swaps the values of x and y. After the swap, x holds the value 10 and y holds the value 5.

Question 11

What does this code return?

print(10 % 3)

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

Correct Answer: a) 1

Explanation: The % operator returns the remainder of the division. 10 % 3 results in 1, because 10 divided by 3 gives a remainder of 1.

Question 12

What is the correct way to define a function in Python?

a) function myFunc():
b) def myFunc():
c) create myFunc():
d) func myFunc():

Correct Answer: b) def myFunc():

Explanation: Functions in Python are defined using the def keyword followed by the function name and parentheses.

Question 13

What does this code output?

print(type(5.0))

a) <class ‘int’>
b) <class ‘float’>
c) <class ‘str’>
d) <class ‘complex’>

Correct Answer: b) <class 'float'>

Explanation: The type() function returns the type of the given object. 5.0 is a floating-point number, so its type is <class 'float'>.

Question 14

What will this code return?

list1 = [1, 2, 3]

list2 = list1

list2.append(4)

print(list1)

a) [1, 2, 3]
b) [1, 2, 3, 4]
c) [4]
d) Error

Correct Answer: b) [1, 2, 3, 4]

Explanation: In Python, lists are mutable and variables can refer to the same object. Since list2 is a reference to list1, appending to list2 will also modify list1.

Question 15

What is the output of this code?

print(bool(0))

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

Correct Answer: b) False

Explanation: In Python, 0 is considered False when converted to a Boolean. Non-zero numbers are considered True.

Question 16

What is the result of this Python code?

print(2 * 3 ** 2)

a) 36
b) 18
c) 12
d) 9

Correct Answer: b) 18

Explanation: Exponentiation is done before multiplication, so 3 ** 2 = 9, and then 2 * 9 = 18.

Question 17

Which of the following is the correct syntax for a comment in Python?

a) // This is a comment
b) /* This is a comment */
c) # This is a comment
d) <– This is a comment –>

Correct Answer: c) # This is a comment

Explanation: In Python, comments start with the # symbol. Anything after the # on the same line is ignored by the interpreter.

Question 18

What will this code output?

name = “Bob”

print(name * 3)

a) BobBobBob
b) Bob 3
c) Bob
d) Error

Correct Answer: a) BobBobBob

Explanation: In Python, the * operator can be used to repeat a string a specified number of times. In this case, 'Bob' is repeated 3 times.

Question 19

What will the following Python code return?

print(bool(“False”))

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

Correct Answer: a) True

Explanation: In Python, non-empty strings are considered True when evaluated in a Boolean context, even if the string is "False".

Question 20

Which of the following data types is immutable in Python?

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

Correct Answer: d) Tuple

Explanation: Tuples in Python are immutable, meaning their elements cannot be changed once the tuple is created. Lists, dictionaries, and sets are mutable.

Complete the Captcha to view next question set.

Tags

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