1/38
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Which function should be used to add data to a file, such as a network configuration file?
write()
3 multiple choice options
Based on the Python code snippet:
def greet(name, greeting = "Welcome to WGU"):
return f"{greeting}, {name}!"
What is the purpose of the first line of code?
To define a function with a default greeting
3 multiple choice options
This Python code snippet returns a syntax error when run:
def multiply_numbers(num1, num2)
result = num1 * num2
return result
num1 = 5
num2 = 8
print(multiply_numbers(num1, num2))
Which code adjustment will resolve the syntax error?
Add a colon after def multiply_numbers(num1, num2).
3 multiple choice options
Based on the Python snippet:
devices = ["router01", "switch01", "modem01", "gateway01", "printer01"]
Which data structure is being used to store the names for various types of devices within devices?
List
3 multiple choice options
Based on the Python snippet:
value = input("Enter a number: ")
result = int(value) + 10
print(result)
What purpose does result = int(value) + 10 serve?
Converts the user's input into an integer and sums it
3 multiple choice options
A developer is creating a Python script to capture metrics for different network interfaces on a router, with each set of metrics treated as a single, immutable record. The stored record will represent a snapshot of metrics for a specific network interface at a given point in time to capture historical records for future analysis.
Which data structure should be used to store the recorded metrics based on the specifications?
Tuple
3 multiple choice options
Based on the Python list:
numbers = [10, 20, 30, 40]
What is the index position of the element "40"?
numbers[3]
3 multiple choice options
Which characteristics are associated with tuples in Python?
Ordered and unchangeable
3 multiple choice options
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.”)
Missing colons at the end of if and else lines
3 multiple choice options
What will be the result of this Python expression?
result = 5 + 3 * 2
11
3 multiple choice options
What is the purpose of the is operator in Python?
To check if two variables refer to the same object in memory
3 multiple choice options
What is the result of this Python expression?
bool(0)
False
2 multiple choice options
Which method is used to return the number of elements in a list?
len()
3 multiple choice options
Which of the following is used to declare a function in Python?
def
3 multiple choice options
What is the output of the following code?
print(3 ** 2)
9
3 multiple choice options
How can you convert the string “123” into an integer in Python?
int("123")
3 multiple choice options
What is the default value of the step parameter in Python’s string slicing?
1
3 multiple choice options
Which of the following methods removes whitespaces from the beginning and the end of a string in Python?
strip()
3 multiple choice options
What will be the result of this Python code?
fruits = [‘apple’, ‘banana’, ‘cherry’]
print(fruits[-1])
cherry
3 multiple choice options
Which of the following creates a dictionary in Python?
{key: value}
3 multiple choice options
Which Python method is used to add an item to the end of a list?
append()
3 multiple choice options
Which operator is used to check if an element exists in a list?
in
3 multiple choice options
What is the output of the following code?
print(“Hello” + “World”)
HelloWorld
1 multiple choice option
How would you access the value associated with the key “name” in the dictionary below?
person = {“name”: “John”, “age”: 30}
person["name"]
3 multiple choice options
Which Python method is used to combine two lists?
extend()
3 multiple choice options
What is the output of this Python code?
numbers = [1, 2, 3]
numbers[0] = 10
print(numbers)
[10, 2, 3]
2 multiple choice options
What will this code return?
my_str = “Hello World”
print(my_str[0:5])
Hello
3 multiple choice options
What does this Python code output?
print(2 * 3 ** 2)
18
3 multiple choice options
How can you create a tuple in Python?
(1, 2, 3)
3 multiple choice options
Which of the following is not a valid Python data type?
array
3 multiple choice options
Which keyword is used to define a class in Python?
class
3 multiple choice options
What does the following Python expression return?
len([10, 20, 30])
3
3 multiple choice options
Which of the following Python keywords is used to create a loop?
for
3 multiple choice options
How do you remove an element from a list in Python?
remove()
3 multiple choice options
What does the continue statement do in Python loops?
Skips the current iteration and moves to the next
3 multiple choice options
What is the output of this code?
my_str = “Hello”
print(my_str[-1])
o
3 multiple choice options
What does this Python code return?
x = 7
y = 5
print(x % y)
2
3 multiple choice options
How do you declare an empty set in Python?
set()
3 multiple choice options
What is the output of the following Python code?
x = 5
y = 10
print(x == y)
False
3 multiple choice options