Question: hello please help me with these question. question 4 Question 4 (10 points) Using print() statements, determine the location of the problem in this function

hello please help me with these question.

question 4

Question 4 (10 points)

Using print() statements, determine the location of the problem in this function

  1. Insert at least 1 print("DEBUG: ...") statement in the code provided for debugging purposes
  2. Use the information provided to debug and correct the code.

NOTE: LEAVE THE PRINT STATEMENTS IN THE CODE EVEN AFTER YOU CORRECT THE CODE

You must include the text string "DEBUG:" in your debugging print statements

Answers should be:

  • student1: 89.60
  • student2: 90.00
  • student3: 76.60
  • Class average: 85.40

Question 4 - ANSWERS

In[1]:

# INSERT PRINT() STATEMENTS IN THE CODE BELOW  """ Purpose: 1. Calculate the average grade for each student 2. Calculate the avgeage grade for the class (3 students) """  student_grades = { "student1": [80, 82, 91, 95, 100], "student2": [85, 85, 95, 95, 90], "student3": [75, 68, 82, 78, 80] }  student_count = 0 student_total = 0 student_avg = 0  class_total = 0 class_avg = 0  for student, grades in student_grades.items(): for grade in grades: student_total += grade # Calculate student average student_avg = student_total / len(grades) # Display each student's name and average print(f'{student}: {student_avg:.2f}') student_count += 1 # Add student total to class total class_total += student_total  # Calculate class average class_avg = class_total / student_count  # Display class average print(f'Class average: {class_avg:.2f}') student1: 89.60 student2: 179.60 student3: 256.20 Class average: 427.00 

Question 5 (5 points)

Describe at least 2 problems you found & fixed in the code provided in Question 4 (above)

Question 5 - ANSWERS

In[44]:

# INSERT YOUR ANSWERS HERE # 1. Problem 1 was ... # 2. Problem 2 was ... 

Python Debugging with Logging

Logging can be used to trace the flow of your code and to flag events using different severity levels:

  • logging.info()
  • logging.debug()
  • logging.warning()
  • logging.error()
  • logging.exception()
  • logging.critical()

Question 6 (10 points)

Try some simple logging to the console

  1. Create a DEBUG logger message: 'This is a DEBUG message. Is this the code bug?'
  2. Create an INFO logger message: 'This is an INFO message. This is CSC 221 Lab2.'
  3. Create a WARNING logger message: 'This is a WARNING message. Be careful.'
  4. Create an ERROR logger message: 'This is an ERROR message. Houston - we have a PROBLEM!'
  5. Create a CRITICAL logger message: 'This is a CRITICAL message. OMG - Hit the brakes!!!'

REFERENCE:https://docs.python.org/3/howto/logging.html

Question 6 - ANSWERS

In[3]:

""" Generate a variety of logging messages """ import logging  logger = logging.getLogger('Lab2_ConsoleLog') logger.setLevel(logging.ERROR)  # INSERT YOUR CODE HERE  

Question 7 (5 points)

Why do we only see the ERROR & CRITICAL logging messages in Question 6?

Question 7 - ANSWERS

In[5]:

# INSERT YOUR ANSWER HERE # We only see ERROR & CRITICAL logging messages because ... 

Question 8 (10 points)

Try some simple logging to the console and a file

Use the sample code provided at the REFERENCE URL provided as a guide

  1. Set the logginglevelto logging.WARNING
  2. Set thefilenameto 'CSC221Lab2.log'
  3. SetLOGGER_NAMEto 'Lab2_FileLogger'
  4. Create a DEBUG logger message: 'This is a DEBUG message. Is this the code bug?'
  5. Create an INFO logger message: 'This is an INFO message. This is CSC 221 Lab2.'
  6. Create a WARNING logger message: 'This is a WARNING message. Be careful.'
  7. Create an ERROR logger message: 'This is an ERROR message. Houston - we have a PROBLEM!'
  8. Create a CRITICAL logger message: 'This is a CRITICAL message. OMG - Hit the brakes!!!'

REFERENCE:https://gist.github.com/wassname/d17325f36c36fa663dd7de3c09a55e74

Question 8 - ANSWERS

In[4]:

""" Generate a variety of logging messages to the console and a log file """ import logging import sys  # INSERT YOUR CODE HERE  

Question 9 (5 points)

How many of the message levels go to the console & file in Question 8?

Which message levels are displayed?

Question 9 - ANSWERS

In[4]:

# INSERT YOUR ANSWER HERE # The number of message levels displayed in console & file are: ____ # List the message levels:  

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!