Book Appointment Now
Troubleshooting and Debugging Techniques Coursera Quiz Answers
Table of Contents
All Weeks Troubleshooting and Debugging Techniques Coursera Quiz Answers
Troubleshooting and Debugging Techniques Week 01 Quiz Answers
Practice Quiz: Binary Searching a Problem
Q1. You have a list of computers that a script connects to in order to gather SNMP traffic and calculate an average for a set of metrics. The script is now failing, and you do not know which remote computer is the problem. How would you troubleshoot this issue using the bisecting methodology?
- Run the script with the first half of the computers.
- Run the script with last computer on the list.
- Run the script with first computer on the list
- Run the script with two-thirds of the computers.
Q2. The find_item function uses binary search to recursively locate an item in the list, returning True if found, False otherwise. Something is missing from this function. Can you spot what it is and fix it? Add debug lines where appropriate, to help narrow down the problem.
def find_item(list, item):
list.sort()
#Returns True if the item is in the list, False if not.
if len(list) == 0:
return False ## OK
#Is the item in the center of the list?
middle = len(list)//2 ## OK
if list[middle] == item:
return True ## OK
#Is the item in the first half of the list?
## if item < list[middle]: ## Incorrect
if item in list[:middle]:
#Call the function with the first half of the list
return find_item(list[:middle], item) ## OK
else:
#Call the function with the second half of the list
return find_item(list[middle+1:], item) ## OK
return False
#Do not edit below this line - This code helps check your work!
list_of_names = ["Parker", "Drew", "Cameron", "Logan", "Alex", "Chris", "Terry", "Jamie", "Jordan", "Taylor"]
print(find_item(list_of_names, "Alex")) ## True
print(find_item(list_of_names, "Andrew")) ## False
print(find_item(list_of_names, "Drew")) ## True
print(find_item(list_of_names, "Jared")) ## False
Output:
True
False
True
False
Q3. The binary_search function returns the position of key in the list if found, or -1 if not found. We want to make sure that it’s working correctly, so we need to place debugging lines to let us know each time that the list is cut in half, whether we’re on the left or the right. Nothing needs to be printed when the key has been located.
For example, binary_search([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3) first determines that the key, 3, is in the left half of the list, and prints “Checking the left side”, then determines that it’s in the right half of the new list and prints “Checking the right side”, before returning the value of 2, which is the position of the key in the list.
Add commands to the code, to print out “Checking the left side” or “Checking the right side”, in the appropriate places.
def binary_search(list, key):
#Returns the position of key in the list if found, -1 otherwise.
#List must be sorted:
list.sort()
left = 0
right = len(list) - 1
while left <= right:
middle = (left + right) // 2
if list[middle] == key:
return middle
if list[middle] > key:
print("Checking the left side")
right = middle - 1
if list[middle] < key:
print("Checking the right side")
left = middle + 1
return -1
print(binary_search([10, 2, 9, 6, 7, 1, 5, 3, 4, 8], 1))
"""Should print 2 debug lines and the return value:
Checking the left side
Checking the left side
0
"""
print(binary_search([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5))
"""Should print no debug lines, as it's located immediately:
4
"""
print(binary_search([10, 9, 8, 7, 6, 5, 4, 3, 2, 1], 7))
"""Should print 3 debug lines and the return value:
Checking the right side
Checking the left side
Checking the right side
6
"""
print(binary_search([1, 3, 5, 7, 9, 10, 2, 4, 6, 8], 10))
"""Should print 3 debug lines and the return value:
Checking the right side
Checking the right side
Checking the right side
9
"""
print(binary_search([5, 1, 8, 2, 4, 10, 7, 6, 3, 9], 11))
"""Should print 4 debug lines and the "not found" value of -1:
Checking the right side
Checking the right side
Checking the right side
Checking the right side
-1
"""
Output:
Checking the left side
Checking the left side
0
4
Checking the right side
Checking the left side
Checking the right side
6
Checking the right side
Checking the right side
Checking the right side
9
Checking the right side
Checking the right side
Checking the right side
Checking the right side
-1
Q4. When trying to find an error in a log file or output to the screen, what command can we use to review, say, the first 10 lines?
- wc
- tail
- head
- bisect
Q5. The best_search function compares linear_search and binary_search functions, to locate a key in the list, and returns how many steps each method took, and which one is the best for that situation. The list does not need to be sorted, as the binary_search function sorts it before proceeding (and uses one step to do so). Here, linear_search and binary_search functions both return the number of steps that it took to either locate the key, or determine that it’s not in the list. If the number of steps is the same for both methods (including the extra step for sorting in binary_search), then the result is a tie. Fill in the blanks to make this work.
def linear_search(list, key):
#Returns the number of steps to determine if key is in the list
#Initialize the counter of steps
steps=0
for i, item in enumerate(list):
steps += 1
if item == key:
break
return steps
def binary_search(list, key):
#Returns the number of steps to determine if key is in the list
#List must be sorted:
list.sort()
#The Sort was 1 step, so initialize the counter of steps to 1
steps=1
left = 0
right = len(list) - 1
while left <= right:
steps += 1
middle = (left + right) // 2
if list[middle] == key:
break
if list[middle] > key:
right = middle - 1
if list[middle] < key:
left = middle + 1
return steps
def best_search(list, key):
steps_linear = linear_search(list, key)
steps_binary = binary_search(list, key)
results = "Linear: " + str(steps_linear) + " steps, "
results += "Binary: " + str(steps_binary) + " steps. "
if (steps_linear < steps_binary):
results += "Best Search is Linear."
elif (steps_linear > steps_binary):
results += "Best Search is Binary."
else:
results += "Result is a Tie."
return results
print(best_search([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 1))
#Should be: Linear: 1 steps, Binary: 4 steps. Best Search is Linear.
print(best_search([10, 2, 9, 1, 7, 5, 3, 4, 6, 8], 1))
#Should be: Linear: 4 steps, Binary: 4 steps. Result is a Tie.
print(best_search([10, 9, 8, 7, 6, 5, 4, 3, 2, 1], 7))
#Should be: Linear: 4 steps, Binary: 5 steps. Best Search is Linear.
print(best_search([1, 3, 5, 7, 9, 10, 2, 4, 6, 8], 10))
#Should be: Linear: 6 steps, Binary: 5 steps. Best Search is Binary.
print(best_search([5, 1, 8, 2, 4, 10, 7, 6, 3, 9], 11))
#Should be: Linear: 10 steps, Binary: 5 steps. Best Search is Binary.
Output:
Linear: 1 steps, Binary: 4 steps. Best Search is Linear.
Linear: 4 steps, Binary: 4 steps. Result is a Tie.
Linear: 4 steps, Binary: 5 steps. Best Search is Linear.
Linear: 6 steps, Binary: 5 steps. Best Search is Binary.
Linear: 10 steps, Binary: 5 steps. Best Search is Binary.
Practice Quiz: Introduction to Debugging
Q1. What is part of the final step when problem-solving?
- Documentation
- Long-term remediation
- Finding the root cause
- Gathering information
Q2. Which tool can you use when debugging to look at library calls made by the software?
- top
- strace
- tcpdump
- ltrace
Q3. What is the first step of problem solving?
- Prevention
- Gathering information
- Long-term remediation
- Finding the root cause
Q4. What software tools are used to analyze network traffic to isolate problems? (Check all that apply)
- tcpdump
- wireshark
- strace
- top
Q5. The strace (in Linux) tool allows us to see all of the _ our program has made.
- Network traffic
- Disk writes
- System calls
- Connection requests
Practice Quiz: Understanding the Problem
Q1. When a user reports that an “application doesn’t work,” what is an appropriate follow-up question to gather more information about the problem?
- Is the server plugged in?
- Why do you need the application?
- Do you have a support ticket number?
- What should happen when you open the app?
Q2. What is a heisenbug?
- The observer effect.
- A test environment.
- The root cause.
- An event viewer.
Q3. The compare_strings function is supposed to compare just the alphanumeric content of two strings, ignoring upper vs lower case and punctuation. But something is not working. Fill in the code to try to find the problems, then fix the problems.
import re
def compare_strings(string1, string2):
#Convert both strings to lowercase
#and remove leading and trailing blanks
string1 = string1.lower().strip()
string2 = string2.lower().strip()
#Ignore punctuation
## punctuation = r"[.?!,;:-']"
punctuation = r"[.?!,;:'-]"
string1 = re.sub(punctuation, r"", string1)
string2 = re.sub(punctuation, r"", string2)
#DEBUG CODE GOES HERE
"""
change r"[.?!,;:-']" with r"[.?!,;:'-]" in punctuation variable
because of pattern error (Character range is out of order ('-' pattern))
"""
return string1 == string2
print(compare_strings("Have a Great Day!", "Have a great day?")) ## True
print(compare_strings("It's raining again.", "its raining, again")) ## True
print(compare_strings("Learn to count: 1, 2, 3.", "Learn to count: one, two, three.")) ## False
print(compare_strings("They found some body.", "They found somebody.")) ## False
Output:
True
True
False
False
Q4. How do we verify if a problem is still persisting or not?
- Restart the device or server hardware
- Attempt to trigger the problem again by following the steps of our reproduction case
- Repeatedly ask the user
- Check again later
Q5. The DateTime module supplies classes for manipulating dates and times and contains many types, objects, and methods. You’ve seen some of them used in the dow function, which returns the day of the week for a specific date. We’ll use them again in the next_date function, which takes the date_string parameter in the format of “year-month-day”, and uses the add_year function to calculate the next year that this date will occur (it’s 4 years later for the 29th of February during Leap Year, and 1 year later for all other dates). Then it returns the value in the same format as it receives the date: “year-month-day”.
Can you find the error in the code? Is it in the next_date function or the add_year function? How can you determine if the add_year function returns what it’s supposed to? Add debug lines as necessary to find the problems, then fix the code to work as indicated above.
import datetime
from datetime import date
def add_year(date_obj):
try:
new_date_obj = date_obj.replace(year = date_obj.year + 1)
except ValueError:
## This gets executed when the above method fails,
## which means that we're making a Leap Year calculation
new_date_obj = date_obj.replace(year = date_obj.year + 4)
return new_date_obj ## OK
def next_date(date_string):
## Convert the argument from string to date object
date_obj = datetime.datetime.strptime(date_string, r"%Y-%m-%d")
next_date_obj = add_year(date_obj)
## print(f'{date_obj} | {next_date_obj}') ## OK
## Convert the datetime object to string,
## in the format of "yyyy-mm-dd"
## next_date_string = next_date_obj.strftime("yyyy-mm-dd")
next_date_string = next_date_obj.strftime("%Y-%m-%d")
return next_date_string
today = date.today() ## Get today's date
print(next_date(str(today)))
## Should return a year from today, unless today is Leap Day
print(next_date("2021-01-01")) ## Should return 2022-01-01
print(next_date("2020-02-29")) ## Should return 2024-02-29
Output:
2020-08-03 00:00:00 | 2021-08-03 00:00:00
2021-08-03
2021-01-01 00:00:00 | 2022-01-01 00:00:00
2022-01-01
2020-02-29 00:00:00 | 2024-02-29 00:00:00
2024-02-29
Quiz Answers: Binary Searching a Problem
Q1. When searching for more than one element in a list, which of the following actions should you perform first in order to search the list as quickly as possible?
- Sort the list
- Do a binary search
- Do a linear search
- Use a base three logarithm
Troubleshooting and Debugging Techniques Week 02 Quiz Answers
Practice Quiz: Slow Code
Q1. Which of the following is NOT considered an expensive operation?
- Parsing a file
- Downloading data over the network
- Going through a list
- Using a dictionary
Q2. Which of the following may be the most expensive to carry out in most automation tasks in a script?
- Loops
- Lists
- Vector
- Hash
Q3. Which of the following statements represents the most sound advice when writing scripts?
- Aim for every speed advantage you can get in your code
- Use expensive operations often
- Start by writing clear code, then speed it up only if necessary
- Use loops as often as possible
Q4. In Python, what is a data structure that stores multiple pieces of data, in order, which can be changed later?
- A hash
- Dictionaries
- Lists
- Tuples
Q5. What command, keyword, module, or tool can be used to measure the amount of time it takes for an operation or program to execute? (Check all that apply)
- time
- kcachegrind
- cProfile
- break
Practice Quiz: Understanding Slowness
Q1. Which of the following will an application spend the longest time retrieving data from?
- CPU L2 cache
- RAM
- Disk
- The network
Q2. Which tool can you use to verify reports of ‘slowness’ for web pages served by a web server you manage?
- The top tool
- The ab tool
- The nice tool
- The pidof tool
Q3. If our computer running Microsoft Windows is running slow, what performance monitoring tools can we use to analyze our system resource usage to identify the bottleneck? (Check all that apply)
- Performance Monitor
- Resource Monitor
- Activity Monitor
- top
Q4. Which of the following programs is likely to run faster and more efficiently, with the least slowdown?
- A program with a cache stored on a hard drive
- A program small enough to fit in RAM
- A program that reads files from an optical disc
- A program that retrieves most of its data from the Internet
Q5. What might cause a single application to slow down an entire system? (Check all that apply)
- A memory leak
- The application relies on a slow network connection
- Handling files that have grown too large
- Hardware faults
Practice Quiz: When Slowness Problems Get Complex
Q1. Which of the following can cache database queries in memory for faster processing of automated tasks?
- Threading
- Varnish
- Memcached
- SQLite
Q2. What module specifies parts of a code to run in separate asynchronous events?
- Threading
- Futures
- Asyncio
- Concurrent
Q3. Which of the following allows our program to run multiple instructions in parallel?
- Threading
- Swap space
- Memory addressing
- Dual SSD
Q4. What is the name of the field of study in computer science that concerns itself with writing programs and operations that run in parallel efficiently?
- Memory management
- Concurrency
- Threading
- Performance analysis
Q5. What would we call a program that often leaves our CPU with little to do as it waits on data from a local disk and the Internet?
- Memory-bound
- CPU-bound
- User-bound
- I/O bound
Troubleshooting and Debugging Techniques Week 03 Quiz Answers
Practice Quiz: Code that Crashes
Q1. Which of the following will let code run until a certain line of code is executed?
- Breakpoints
- Watchpoints
- Backtrace
- Pointers
Q2. Which of the following is NOT likely to cause a segmentation fault?
- Wild pointers
- Reading past the end of an array
- Stack overflow
- RAM replacement
Q3. A common error worth keeping in mind happens often when iterating through arrays or other collections, and is often fixed by changing the less than or equal sign in our for loop to be a strictly less than sign. What is this common error known as?
- Segmentation fault
- backtrace
- The No such file or directory error
- Off-by-one error
Q4. A very common method of debugging is to add print statements to our code that display information, such as contents of variables, custom error statements, or return values of functions. What is this type of debugging called?
- Backtracking
- Log review
- Printf debugging
- Assertion debugging
Q5. When a process crashes, the operating system may generate a file containing information about the state of the process in memory to help the developer debug the program later. What are these files called?
- Log files
- Core files
- Metadata file
- Cache file
Practice Quiz: Handling Bigger Incidents
Q1. Which of the following would be effective in resolving a large issue if it happens again in the future?
- Incident controller
- Postmortem
- Rollbacks
- Load balancers
Q2. During peak hours, users have reported issues connecting to a website. The website is hosted by two load balancing servers in the cloud and are connected to an external SQL database. Logs on both servers show an increase in CPU and RAM usage. What may be the most effective way to resolve this issue with a complex set of servers?
- Use threading in the program
- Cache data in memory
- Automate deployment of additional servers
- Optimize the database
Q3. It has become increasingly common to use cloud services and virtualization. Which kind of fix, in particular, does virtual cloud deployment speed up and simplify?
- Deployment of new servers
- Application code fixes
- Log reviewing
- Postmortems
Q4. What should we include in our postmortem? (Check all that apply)
- Root cause of the issue
- How we diagnosed the problem
- How we fixed the problem
- Who caused the problem
Q5. In general, what is the goal of a postmortem? (Check all that apply)
- To identify who is at fault
- To allow prevention in the future
- To allow speedy remediation of similar issues in the future
- To analyze all system bugs
Practice Quiz: Why Programs Crash
Q1. When using Event Viewer on a Windows system, what is the best way to quickly access specific types of logs?
- Export logs
- Create a custom view
- Click on System Reports
- Run the head command
Q2. An employee runs an application on a shared office computer, and it crashes. This does not happen to other users on the same computer. After reviewing the application logs, you find that the employee didn’t have access to the application. What log error helped you reach this conclusion?
- “No such file or directory”
- “Connection refused”
- “Permission denied”
- “Application terminated”
Q3. What tool can we use to check the health of our RAM?
- Event Viewer
- S.M.A.R.T. tools
- memtest86
- Process Monitor
Q4. You’ve just finished helping a user work around an issue in an application. What important but easy-to-forget step should we remember to do next?
- Fix the code
- Report the bug to the developers
- Reinstall the program
- Change the user’s password
Q5. A user is experiencing strange behavior from their computer. It is running slow and lagging, and having momentary freeze-ups that it does not usually have. The problem seems to be system-wide and not restricted to a particular application. What is the first thing to ask the user as to whether they have tried it?
- Adding more RAM
- Reinstalling Windows
- Identified the bottleneck with a resource monitor
- Upgrade their HDD to an SSD
Troubleshooting and Debugging Techniques Week 04 Quiz Answers
Practice Quiz: Making Our Future Lives Easier
Q1. Which proactive practice can you implement to make troubleshooting issues in a program easier when they happen again, or face other similar issues?
- Create and update documentation
- Use a test environment.
- Automate rollbacks.
- Set up Unit tests.
Q2. Which of the following is a good example of mixing and matching resources on a single server so that the running services make the best possible use of all resources?
- Run two applications that are CPU intensive between two servers.
- Run a CPU intensive application on one server, and an I/O intensive application on another server.
- Run a RAM intensive application and a CPU intensive application on a server.
- Run two applications that are RAM and I/O intensive on a server.
Q3. One strategy for debugging involves explaining the problem to yourself out loud. What is this technique known as?
- Monitoring
- Rubber Ducking
- Testing
- Ticketing
Q4. When deploying software, what is a canary?
- A test for how components of a program interact with each other
- A test of a program’s components
- A test deployment to a subset of production hosts
- A small section of code
Q5. It is advisable to collect monitoring information into a central location. Given the importance of the server handling the centralized collecting, when assessing risks from outages, this server could be described as what?
- A failure domain
- A problem domain
- CPU intensive
- I/O intensive
Practice Quiz: Managing Computer Resources
Q1. How can you profile an entire Python application?
- Use an @profile label
- Use the guppy module
- Use Memory Profiler
- Use a decorator
Q2. Your application is having difficulty sending and receiving large packets of data, which are also delaying other processes when connected to remote computers. Which of the following will be most effective on improving network traffic for the application?
- Running the iftop program
- Increase storage capacity
- Increase memory capacity
- Use traffic shaping
Q3. What is the term referring to the amount of time it takes for a request to reach its destination, usually measured in milliseconds (ms)?
- Bandwidth
- Latency
- Number of connections
- Traffic shaping
Q4. If your computer is slowing down, what Linux program might we use to determine if we have a memory leak and what process might be causing it?
- top
- gparted
- iftop
- cron
Q5. Some programs open a temporary file, and immediately _ the file before the process finishes, then the file continues to grow, which can cause slowdown.
- open
- close
- delete
- write to
Practice Quiz: Managing Our Tim
Q1. Using the Eisenhower Decision Matrix, which of the following is an example of an event or task that is both Important, and Urgent?
- Office gossip
- Replying to emails
- Internet connection is down
- Follow-up to a recently resolved issue
Q2. You’re working on a web server issue that’s preventing all users from accessing the site. You then receive a call from user to reset their user account password. Which appropriate action should you take when prioritizing your tasks?
- Reset the user’s password
- Create a script to automate password resets
- Ask the user to open a support ticket.
- Ignore the user, and troubleshoot web server.
Q3. What is it called when we make more work for ourselves later by taking shortcuts now?
- Technical debt
- Ticket tracking
- Eisenhower Decision Matrix
- Automation
Q4. What is the first step of prioritizing our time properly?
- Work on urgent tasks first
- Assess the importance of each issue
- Make a list of all tasks
- Estimate the time each task will take
Q5. If an issue isn’t solved within the time estimate that you provided, what should you do? (Select all that apply)
- Explain why
- Drop everything and perform that task immediately
- Give an updated time estimate
- Put the task at the end of the list
Next Course Quiz Answers >>
Configuration Management and the Cloud
<< Previous Quiz Answers
Introduction to Git and GitHub
All Quiz Answers of Google IT Automation with Python Professional Certificate
Course 1: Crash Course on Python Coursera Quiz Answers
Course 2: Using Python to interact with the Operating System
Course 3: Introduction to Git and GitHub
Course 4: Troubleshooting and Debugging Techniques
Course 5: Configuration Management and the Cloud
Course 6: Automating Real-World Tasks with Python