🌍 All Study Guides📊 Dashboard📰 Blog💡 About
Google IT Automation with Python Professional Certificate • STUDY MODE

PRACTICE QUIZ

QUESTION 1 OF 39

A programmer is working on a new project and encounters a complex problem. They are tempted to spend a lot of time trying to solve the problem on their own. However, a colleague advises them to research existing solutions first. What is the colleague's advice based on?

A
The colleague believes that the programmer should not trust their own abilities to solve the problem.
B
The colleague believes that the programmer should not waste time reinventing something that already exists.Correct Answer
C
The colleague believes that the programmer should ask someone with more experience to solve this problem.
D
The colleague believes that the programmer should not try to be innovative.
QUESTION 2 OF 39

Based on the following code, what is the correct output? numbers = [ 4, 6, 2, 7, 1 ] numbers.sort() print(numbers)

A
7, 6, 4, 2, 1
B
1, 2, 4, 6, 7Correct Answer
C
1, 2, 6, 7, 4
D
4, 6, 2, 7, 1
QUESTION 3 OF 39

What is the sort() method used for in Python?

A
The sort() method returns the list from the code.
B
The sort() method sorts a list without creating a new list.Correct Answer
C
The sort() method creates a new list by sorting the strings or values in the original list.
D
The sort() method returns a new list that’s been sorted.
QUESTION 4 OF 39

You want to sort the following list in descending order. What is the correct code to use to do this? numbers = [ 4, 6, 2, 7, 1 ]

A
numbers.sort()
B
numbers.sort(reverse = False)
C
numbers.sort(backup = True)
D
numbers.sort(reverse = True)Correct Answer
QUESTION 5 OF 39

You need to sort a list of strings based on their length, what argument would you use to do this?

A
key=lenCorrect Answer
B
sort(len)
C
key=length
D
sorted(len)
QUESTION 6 OF 39

Which of the following statements are true about Python dictionaries? Select all that apply.

A
Dictionaries are an ordered collection of key-value pairs.
B
Dictionaries are mutable data structures.Correct Answer
C
Dictionaries are used to store data that needs to be accessed quickly and efficiently.Correct Answer
D
Values in a dictionary can be Python objects.Correct Answer
QUESTION 7 OF 39

Which of the following best describes the purpose of an if statement in Python?

A
To store data in a temporary variable
B
To execute a block of code only if a certain condition is trueCorrect Answer
C
To repeat a block of code a certain number of times
D
To define a function that performs a specific task
QUESTION 8 OF 39

A grocery store is developing a loyalty program to reward their customers based on their purchase history. The store wants to assign different reward tiers based on the total amount spent by each customer in the past year. To accomplish this, they need a conditional statement that will execute different blocks of code based on the customer's spending amount. What conditional statement is most suitable for this task?

A
elif statementCorrect Answer
B
true statement
C
and statement
D
if statement
QUESTION 9 OF 39

Take a look at the code snippet below. What is the purpose of the generate_report function? def generate_report(machines): for machine, users in machines.items(): if len(users) > 0: user_list = ", ".join(users) print("{}: {}".format(machine, user_list))

A
To create a new dictionary that contains the same information as the machines dictionary.
B
To sort the machines dictionary by the number of users logged into each machine.
C
To check if there are any users logged into any machines.
D
To generate a report that lists all the machines and the users logged into each machine.Correct Answer
QUESTION 10 OF 39

Why is understanding the problem essential to writing a Python script? Select all that apply.

A
Ensure that you are writing a script that is efficient and effectiveCorrect Answer
B
To write code that will solve the problem in a clear and concise wayCorrect Answer
C
To select which scripting language to use.
D
To identify the inputs and outputs of the problemCorrect Answer
QUESTION 11 OF 39

You need to sort a list in descending order, which argument should you use in your sort() method to do this?

A
reverse = TrueCorrect Answer
B
reverse = False
C
backup = True
D
backup = False
QUESTION 12 OF 39

Based on the following code, what is the correct output? names = ["Carlos", "Ray", "Alex", "Kelly"] print(sorted(names, key=len))

A
['Carlos', 'Ray', 'Alex', 'Kelly']
B
['Ray', 'Alex', 'Kelly', 'Carlos']Correct Answer
C
['Carlos', 'Kelly', 'Alex', 'Ray']
D
['Alex', 'Ray', 'Carlos', 'Kelly']
QUESTION 13 OF 39

A grocery store is tracking the inventory of its products. For each product, the store needs to keep track of the product name, the product ID, the quantity in stock, and the price.

A
A list
B
A set
C
A dictionaryCorrect Answer
D
A tuple
QUESTION 14 OF 39

A software engineer is tasked with developing a system that monitors network traffic and alerts administrators when suspicious activity is detected. The system receives a continuous stream of network traffic data, which needs to be processed and analyzed in real-time. The engineer is unsure of the best way to handle this high-volume data stream efficiently. What should the programmer do?

A
Use a third-party library or tool designed for real-time data processing.
B
Create 2 separate functions to process the events and print the associated data to the screen.Correct Answer
C
Create one function to process the events and print the associated data to the screen.
D
Increase the size of the database server.
QUESTION 15 OF 39

What does the following code snippet do? if event.type == "login": machines[event.machine].add(event.user)

A
It removes the user from the list of logged-in users for the specified machine.
B
It checks if the event type is “logout” and if so, removes the user from the list of logged-in users for the specified machine.
C
It checks if the event type is “login” and if so, adds the user to the list of logged-in users for a specified machine.Correct Answer
D
It adds the user to the list of logged-in users for the specified machine.
QUESTION 16 OF 39

Based on the following code, what is the correct output? numbers = [ 3, 5, 4, 8, 1 ] numbers.sort() print(numbers)

A
3, 5, 4, 8, 1
B
1, 3, 4, 5, 8Correct Answer
C
8, 5, 4, 3, 1
D
3, 1, 5, 4, 8
QUESTION 17 OF 39

What is the purpose of the argument key=len in a Python script?

A
To sort a list of strings based on their capitalization.
B
To sort a list of strings based on importance.
C
To sort a list of strings based on their length.Correct Answer
D
To sort a list of strings alphabetically.
QUESTION 18 OF 39

A programmer is tasked with developing a program that processes events and prints the associated data to the screen. The programmer is unfamiliar with the most efficient approach to accomplish this task. What should the programmer do?

A
Create one function to process the events and print the associated data to the screen.
B
Create 2 separate functions to process the events and print the associated data to the screen.Correct Answer
C
Increase the size of the database server.
D
Calculate the results of a single function to avoid having to recalculate them for each user.
QUESTION 19 OF 39

Which of the following statements accurately describes the purpose of an elif statement in Python?

A
To combine multiple conditions into a single statement, allowing for more complex decision-making.
B
To repeat a block of code a certain number of times, or until a specific condition is met.
C
To store data in a temporary variable, accessible only if later called on within the script.
D
To execute a block of code if a specific condition is true, otherwise execute an alternative block of code.Correct Answer
QUESTION 20 OF 39

Take a look at the code snippet below. What parameters does this method take in? Select all that apply. class Event: def __init__(self, event_date, event_type, machine_name, user): self.date = event_date self.type = event_type self.machine = machine_name self.user = user

A
event_dateCorrect Answer
B
event_timeCorrect Answer
C
machine_nameCorrect Answer
D
event
QUESTION 21 OF 39

Restate the problem statement from the video example. Right on! This problem statement defines the problem in specific terms and provides a direction and goal.

A
Each login event is an instance of the Event class.
B
The attributes of the Event class are date, user, machine, and type.
C
The company manager wants to know which users are currently connected to which machines.
D
We need to process a list of Event objects using their attributes to generate a report that lists all users currently logged in to the machines.Correct Answer
QUESTION 22 OF 39

There are two standard methods to sort a list in Python, sort and sorted. What is the difference between these two methods? Awesome! So you were paying attention. Knowing the difference between these two methods is not nearly as important as the ability to research the tools we have available to us.

A
sort returns a new list, while sorted returns the same list reorganized.
B
sort lists alphabetically, while sorted lists by word length.
C
sorted returns a new list, while sort returns the same list reorganized.Correct Answer
QUESTION 23 OF 39

Having a plan is half the battle. When planning out your program, why is it often a good idea to separate functions? Great work! Separating functions is helpful when debugging or making other changes, as it keeps functions from getting ‘tangled’. It also makes it easier to adapt functions for other uses.

A
A: It simplifies making changes and fixing bugs.
B
B: It allows us to use the same function for multiple purposes.
C
C: It makes list sorting easier.
D
D: Both A and B.Correct Answer
QUESTION 24 OF 39

It’s important to know why we’ve written a function. In the example used in the video (shown here), what is the purpose of “if len(users) > 0:” ? def generate_report(machines): for machine, users in machines.items(): if len(users) > 0: user_list = ", ".join(users) print("{}: {}".format(machine, user_list)) Awesome! Generating the string underneath this check prevents lists with zero users from being printed.

A
Ensure that we don't print any machines where nobody is currently logged inCorrect Answer
B
Generates a string of logged-in users for a given machine
C
Sorts the list of users
D
Iterate over the keys and values in the dictionary
QUESTION 25 OF 39

Which line from the program we just wrote combines each logged-in user attribute into one variable? Nice job! The join() function of str gathers the user attributes (which is a string) into a single string, with commas separating the users.

A
events.sort(key=get_event_date)
B
self.user = user
C
user_list = ", ".join(users)Correct Answer
D
machines[event.machine].add(event.user)
QUESTION 26 OF 39

A software engineer is tasked with developing a new feature for a popular web application. The feature involves a complex algorithm that requires a significant amount of coding. The engineer is tempted to start writing the code from scratch, but their manager suggests taking a different approach. What is the manager’s recommendation based on?

A
The manager believes that the engineer should not try to be creative.
B
The manager believes that the engineer should not trust their own abilities to solve the problem.
C
The manager believes that the engineer should spend some time researching the problem to identify if a similar problem has been solved before.Correct Answer
D
The manager believes that the software engineer should ask someone with more experience to tackle this problem.
QUESTION 27 OF 39

A system administrator is managing a network of computers. Each computer has a set of users who are currently logged in. The administrator wants to be able to quickly look up the current users of a given computer. Which data structure is the most efficient for storing the current users of each computer?

A
A set
B
A dictionaryCorrect Answer
C
A list
D
A tuple
QUESTION 28 OF 39

Which method is used to sort a list and keep the original list in tact?

A
The sort() method
B
The sorted() method with a reverse argument.
C
The print() method.
D
The sorted() methodCorrect Answer
QUESTION 29 OF 39

A programmer is working on a new project and encounters a complex problem. They are tempted to spend a lot of time trying to solve the problem on their own. However, a colleague advises them to research existing solutions first. What is the colleague’s advice based on?

A
The colleague believes that the programmer should not trust their own abilities to solve the problem.
B
The colleague believes that the programmer should not waste time reinventing something that already exists.Correct Answer
C
The colleague believes that the programmer should ask someone with more experience to solve this problem.
D
The colleague believes that the programmer should not try to be innovative.
QUESTION 30 OF 39

Based on the following code, what is the correct output?

A
7, 6, 4, 2, 1
B
1, 2, 4, 6, 7Correct Answer
C
1, 2, 6, 7, 4
D
4, 6, 2, 7, 1
QUESTION 31 OF 39

A grocery store is developing a loyalty program to reward their customers based on their purchase history. The store wants to assign different reward tiers based on the total amount spent by each customer in the past year. To accomplish this, they need a conditional statement that will execute different blocks of code based on the customer’s spending amount. What conditional statement is most suitable for this task?

A
elif statementCorrect Answer
B
true statement
C
and statement
D
if statement
QUESTION 32 OF 39

Take a look at the code snippet below. What is the purpose of the generate_report function?

A
To create a new dictionary that contains the same information as the machine’s dictionary.
B
To sort the machine’s dictionary by the number of users logged into each machine.
C
To check if there are any users logged into any machines.
D
To generate a report that lists all the machines and the users logged into each machine.Correct Answer
QUESTION 33 OF 39

What does the following code snippet do?

A
It removes the user from the list of logged-in users for the specified machine.
B
It checks if the event type is “logout” and if so, removes the user from the list of logged-in users for the specified machine.
C
It checks if the event type is “login” and if so, adds the user to the list of logged-in users for a specified machine.Correct Answer
D
It adds the user to the list of logged-in users for the specified machine.
QUESTION 34 OF 39

Take a look at the code snippet below. What parameters does this method take in? Select all that apply.

A
event_dateCorrect Answer
B
event_timeCorrect Answer
C
machine_nameCorrect Answer
D
event
QUESTION 35 OF 39

Restate the problem statement from the video example.

A
Each login event is an instance of the Event class.
B
The attributes of the Event class are date, user, machine, and type.
C
The company manager wants to know which users are currently connected to which machines.
D
We need to process a list of Event objects using their attributes to generate a report that lists all users currently logged in to the machines.Correct Answer
QUESTION 36 OF 39

There are two standard methods to sort a list in Python, sort and sorted. What is the difference between these two methods?

A
sort returns a new list, while sorted returns the same list reorganized.
B
sort lists alphabetically, while sorted lists by word length.
C
sorted returns a new list, while sort returns the same list reorganized.Correct Answer
QUESTION 37 OF 39

Having a plan is half the battle. When planning out your program, why is it often a good idea to separate functions?

A
A: It simplifies making changes and fixing bugs.
B
B: It allows us to use the same function for multiple purposes.
C
C: It makes list sorting easier.
D
D: Both A and B.Correct Answer
QUESTION 38 OF 39

It’s important to know why we’ve written a function. In the example used in the video (shown here), what is the purpose of “if len(users) > 0:” ?

A
Ensure that we don’t print any machines where nobody is currently logged inCorrect Answer
B
Generates a string of logged-in users for a given machine
C
Sorts the list of users
D
Iterate over the keys and values in the dictionary
QUESTION 39 OF 39

Which line from the program we just wrote combines each logged-in user attribute into one variable?

A
events.sort(key=get_event_date)
B
self.user = user
C
user_list = “, “.join(users)Correct Answer
D
machines[event.machine].add(event.user)

Ready to test your recall?

A programmer is working on a new project and encounters a complex problem. They are tempted to spend a lot of time trying to solve the problem on their own. However, a colleague advises them to research existing solutions first. What is the colleague's advice based on?

A
The colleague believes that the programmer should not trust their own abilities to solve the problem.
B
The colleague believes that the programmer should not waste time reinventing something that already exists.
C
The colleague believes that the programmer should ask someone with more experience to solve this problem.
D
The colleague believes that the programmer should not try to be innovative.

How confident are you in this answer?