Docsity

WGU D335 Intro to Python Comprehensive Practice Exam, Exams of Information Technology

Toggle sidebar
bg1
WGU D335 Intro to Python – Comprehensive
Practice Exam
1. A named item used to hold a value in a program is called a:
a) Function
b) Variable
c) Loop
d) Operator
CORRECT ANSWER: b) Variable
2. Which of the following is a correct way to create 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`
3. What is the data type of `x` after the assignment `x = 5.0`?
a) int
b) float
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download WGU D335 Intro to Python Comprehensive Practice Exam and more Exams Information Technology in PDF only on Docsity!

WGU D335 Intro to Python – Comprehensive

Practice Exam

  1. A named item used to hold a value in a program is called a:

a) Function

b) Variable

c) Loop

d) Operator

CORRECT ANSWER: b) Variable

  1. Which of the following is a correct way to create 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

  1. What is the data type of x after the assignment x = 5.0?

a) int

b) float

c) str

d) bool

CORRECT ANSWER: b) float

  1. What is the output of print(3 + 2.5)?

a) 5

b) 5.

c) 6

d) Error

CORRECT ANSWER: b) 5.5 (Python performs implicit type conversion)

  1. Which function is used to get text input from a user?

a) print()

b) get()

c) input()

d) scan()

CORRECT ANSWER: c) input()

  1. To convert a string like "123" into an integer, you would use:

a) string()

b) int()

c) float()

CORRECT ANSWER: b) end=' '

  1. What is a Python interpreter?

a) A tool that converts Python code to Java.

b) A program that executes Python code line by line.

c) A text editor for writing code.

d) A compiler that creates an executable file.

CORRECT ANSWER: b) A program that executes Python code line by line.

Module 2: Strings & String Operations

  1. What is a "string literal"?

a) A variable that holds numbers.

b) A sequence of characters enclosed in quotes.

c) A type of loop.

d) A built-in function.

CORRECT ANSWER: b) A sequence of characters enclosed in quotes.

  1. What will be the output of the following code?
my_string = "Hello" print(my_string[1])

a) H

b) e

c) l

d) o

CORRECT ANSWER: b) e (Indexing in Python starts at 0)

  1. The find(x) method in a string returns:

a) The number of times 'x' appears.

b) The index of the first occurrence of 'x'.

c) The index of the last occurrence of 'x'.

d) An error if 'x' is not found.

CORRECT ANSWER: b) The index of the first occurrence of 'x'.

  1. What does the \n character represent in a string?

a) A tab space

b) A new line

c) A backslash

d) The end of a string

CORRECT ANSWER: b) A new line

d) 1

CORRECT ANSWER: b) 3 (// is the floor division operator)

  1. What is the result of 10 % 3?

a) 3

b) 3.

c) 1

d) 0

CORRECT ANSWER: c) 1 (% is the modulus operator, giving the remainder)

  1. Which operator is used for exponentiation?

a) ^

b) ``

c) *

d) ^^

CORRECT ANSWER: b) ``

  1. Following order of operations, what is the result of 3 * (2 + 1)?

a) 7

b) 9

c) 5

d) 6

CORRECT ANSWER: b) 9 (Parentheses have the highest precedence)

  1. What is the value of x after x = abs(-7.5)?

a) -7.

b) 7.

c) -

d) 8

CORRECT ANSWER: b) 7.5 (Absolute value removes the negative sign)

  1. Which comparison operator means "not equal to"?

a) =!

b) &lt;

c) !=

d) &lt;

CORRECT ANSWER: c) !=

  1. What is the Boolean result of 5 10?

a) True

b) False

c) None

d) Error

c) Set

d) Dictionary

CORRECT ANSWER: c) Set

  1. How do you add the element 5 to the end of a list named my_list?

a) my_list.add(5)

b) my_list.insert(5)

c) my_list.append(5)

d) my_list.put(5)

CORRECT ANSWER: c) my_list.append(5)

  1. If my_set = {1, 2, 3}, what happens when you execute my_set.add(2)?

a) The set becomes {1, 2, 2, 3}.

b) The set remains {1, 2, 3}.

c) An error occurs.

d) The set becomes {1, 2, 3, 2}.

CORRECT ANSWER: b) The set remains {1, 2, 3}. (Sets contain only unique elements)

  1. How do you access the value associated with the key "name" in a dictionary person = {'name': 'Alice', 'age': 25}?

a) person[0]

b) person.get("name")

c) person.name

d) Both person["name"] and person.get("name") are valid.

CORRECT ANSWER: d) Both person["name"] and person.get("name") are valid.

  1. What is the output of the following code?
my_list = [10, 20, 30, 40] print(my_list[-1])

a) 10

b) 20

c) 30

d) 40

CORRECT ANSWER: d) 40 (Negative indexes start from the end, -1 is the last item)

  1. The list.pop(i) method does what?

a) Removes the element at index i and returns it.

b) Removes the first element whose value is i.

c) Adds an element at index i.

d) Returns the value at index i without removing it.

CORRECT ANSWER: a) Removes the element at index i and returns it.

  1. A dictionary uses which of the following to organize data?

CORRECT ANSWER: c) for loop

  1. Which loop will execute at least once if the initial condition is false?

a) for loop

b) while loop

c) do-while loop (Note: Python doesn't have a native do-while)

d) None of the above

CORRECT ANSWER: d) None of the above (A while loop condition is checked first, so it may not execute at all. for loops depend on the sequence.)

  1. What does the range(1, 5) function generate?

a) [1, 2, 3, 4, 5]

b) [1, 2, 3, 4]

c) [0, 1, 2, 3, 4]

d) [5, 4, 3, 2, 1]

CORRECT ANSWER: b) [1, 2, 3, 4] (The stop value is exclusive)

  1. The break statement is used to:

a) Skip the rest of the code inside a loop for the current iteration only.

b) Exit a loop entirely.

c) Start the next iteration of a loop.

d) Define a function.

CORRECT ANSWER: b) Exit a loop entirely.

  1. What is the output of the following code?
x = 5 if x 5: print("A") elif x == 5: print("B") else: print("C")

a) A

b) B

c) C

d) None

CORRECT ANSWER: b) B

  1. A while loop repeats as long as:

a) A specific number of iterations is reached.

b) The loop counter is less than 10.

c) A condition is true.

d) A user presses a key.

c) Modules

d) Return values

CORRECT ANSWER: b) Parameters

  1. The value passed into a function during a call (e.g., my_func(5, 10)) is called:

a) A parameter

b) A definition

c) An argument

d) A scope

CORRECT ANSWER: c) An argument

  1. A variable created inside a function has:

a) Global scope

b) Local scope

c) Public scope

d) Module scope

CORRECT ANSWER: b) Local scope

  1. What is a key characteristic of recursion?

a) It uses loops to repeat code.

b) A function calls itself.

c) It is the only way to calculate factorials.

d) It cannot return a value.

CORRECT ANSWER: b) A function calls itself.

  1. What does the return keyword do?

a) Exits the program.

b) Exits the function and sends a value back to the caller.

c) Prints a value to the console.

d) Restarts the function.

CORRECT ANSWER: b) Exits the function and sends a value back to the caller.

Module 7: File I/O, Modules & Error Handling

  1. What does the open() function do in Python?

a) Opens a web browser.

b) Opens a file for reading or writing.

c) Opens a new program window.

d) Opens a connection to a database.

CORRECT ANSWER: b) Opens a file for reading or writing.

  1. If you open a file using with open("file.txt", "r") as f:, what does the "r" stand for?

b) using

c) import

d) require

CORRECT ANSWER: c) import

  1. The if __name__ == "__main__": construct is used to:

a) Check if a function exists.

b) Separate code that should be run only when the script is executed directly, not when imported as a module.

c) Define the main variable of a program.

d) Ensure the program runs on the main thread.

CORRECT ANSWER: b) Separate code that should be run only when the script is executed directly, not when imported as a module.

  1. What is the purpose of a try block?

a) To execute code that might cause an exception.

b) To handle an exception.

c) To define a function.

d) To import a module.

CORRECT ANSWER: a) To execute code that might cause an exception.

  1. A ZeroDivisionError occurs when:

a) You divide by a float.

b) You try to open a file that doesn't exist.

c) You attempt to divide a number by zero.

d) You use an invalid index for a list.

CORRECT ANSWER: c) You attempt to divide a number by zero.

  1. What does the csv module allow you to do?

a) Create complex mathematical formulas.

b) Read and write data in CSV (Comma-Separated Values) format.

c) Manipulate image files.

d) Send emails.

CORRECT ANSWER: b) Read and write data in CSV (Comma-Separated Values) format.