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

What does this Python code output?

print(5 // 2)

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

Correct Answer: a) 2

Explanation: The // operator performs floor division, which returns the largest integer less than or equal to the result.

Question 02

What does the following Python code output?

x = [“a”, “b”, “c”]

x.append(“d”)

print(x)

a) [“a”, “b”, “c”]
b) [“a”, “b”, “c”, “d”]
c) [“a”, “b”, “d”]
d) Error

Correct Answer: b) ["a", "b", "c", "d"]

Explanation: The append() method adds an element to the end of the list.

Question 03

What does the following Python code return?

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

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

Correct Answer: b) 5

Explanation: The len() function returns the number of elements in the list, which is 5 in this case.

Question 04

What does this Python code return?

print(“Hello, World!”.upper())

a) hello, world!
b) HELLO, WORLD!
c) Hello, World!
d) Error

Correct Answer: b) HELLO, WORLD!

Explanation: The upper() method converts all the letters in the string to uppercase.

Question 05

What will this Python code return?

x = [1, 2, 3, 4]

print(x.index(3))

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

Correct Answer: b) 2

Explanation: The index() method returns the index of the first occurrence of the specified value. The value 3 is at index 2.

Question 06

What does this Python code return?

print(2 ** 3)

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

Correct Answer: c) 8

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

Question 07

What will the following Python code output?

fruits = [“apple”, “banana”, “cherry”]

fruits.sort()

print(fruits)

a) [“apple”, “banana”, “cherry”]
b) [“banana”, “apple”, “cherry”]
c) [“cherry”, “banana”, “apple”]
d) Error

Correct Answer: a) ["apple", "banana", "cherry"]

Explanation: The sort() method sorts the list in ascending alphabetical order.

Question 08

What is the output of this Python code?

print(“abc” + “def”)

a) abc
b) abcdef
c) abc def
d) Error

Correct Answer: b) abcdef

Explanation: The + operator concatenates two strings. "abc" + "def" results in "abcdef".

Question 09

What does this Python code return?

print([1, 2, 3].pop())

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

Correct Answer: c) 3

Explanation: The pop() method removes and returns the last item from the list. In this case, 3 is the last item.

Question 10

What will this Python code output?

print(10 % 3)

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

Correct Answer: a) 1

Explanation: The % operator returns the remainder of the division. 10 % 3 equals 1 because 10 divided by 3 leaves a remainder of 1.

Question 11

What does this Python code return?

print(“Python”.startswith(“P”))

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

Correct Answer: a) True

Explanation: The startswith() method checks whether a string starts with a specified prefix. "Python".startswith("P") returns True.

Question 12

What is the output of this Python code?

print(list(range(3)))

a) [0, 1, 2, 3]
b) [1, 2, 3]
c) [0, 1, 2]
d) [1, 2]

Correct Answer: c) [0, 1, 2]

Explanation: The range(3) function generates a sequence of numbers starting from 0 up to but not including 3.

Question 13

What will this Python code output?

print(3 == 3.0)

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

Correct Answer: a) True

Explanation: In Python, 3 and 3.0 are considered equal because Python performs type coercion for numerical comparison.

Question 14

What does this Python code return?

print(“123”.isdigit())

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

Correct Answer: a) True

Explanation: The isdigit() method returns True if all characters in the string are digits. "123" contains only digits, so it returns True.

Question 15

What will this Python code output?

print(2 != 3)

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

Correct Answer: a) True

Explanation: The != operator checks whether two values are not equal. Since 2 is not equal to 3, the result is True.

Question 16

What does this Python code return?

print([1, 2, 3] == [1, 2, 3])

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

Correct Answer: a) True

Explanation: The == operator compares the values of two lists. Since both lists contain the same values in the same order, the result is True.

Question 17

What will be the result of this Python code?

x = [1, 2, 3]

print(len(x))

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

Correct Answer: c) 3

Explanation: The len() function returns the number of elements in a list. x contains three elements, so the result is 3.

Question 18

What does this Python code output?

x = 5

y = “5”

print(str(x) == y)

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

Correct Answer: a) True

Explanation: The str() function converts the integer 5 to the string "5", making the comparison True.

Question 19

What does this Python code return?

x = [1, 2, 3]

y = x

y.append(4)

print(x)

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

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

Explanation: Both x and y refer to the same list in memory. Modifying y also affects x.

Question 20

What does this Python code output?

x = [1, 2, 3]

y = x.copy()

y.append(4)

print(x)

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

Correct Answer: a) [1, 2, 3]

Explanation: The copy() method creates a shallow copy of the list. Modifications to y do not affect the original list x.

Complete the Captcha to view next question set.

Tags

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