Where to add exception handling /u/baliditity Python Education

I am learning python and I think I have a decent grasp in on the functionality of handling errors, however, in this mini project, I am unsure of where to handle the error. Should I handle the error in the main function or in the get_sales function, perhaps both? “` SET DAYS to 7

DEFINE main function: SET days_list to an empty list of size DAYS TRY: CALL get_sales(days_list) EXCEPT: DISPLAY “An error occurred while collecting sales data.” ELSE: SET total to calculate_total(days_list) DISPLAY “The total sales are:”, total

DEFINE get_sales(list): FOR index in range(len(list)): GET sales from user SET list[index] to the entered sales value RETURN list

DEFINE calculate_total(list): SET total to 0 FOR value in list: ADD value to total RETURN total “`

submitted by /u/baliditity
[link] [comments]

​r/learnpython I am learning python and I think I have a decent grasp in on the functionality of handling errors, however, in this mini project, I am unsure of where to handle the error. Should I handle the error in the main function or in the get_sales function, perhaps both? “` SET DAYS to 7 DEFINE main function: SET days_list to an empty list of size DAYS TRY: CALL get_sales(days_list) EXCEPT: DISPLAY “An error occurred while collecting sales data.” ELSE: SET total to calculate_total(days_list) DISPLAY “The total sales are:”, total DEFINE get_sales(list): FOR index in range(len(list)): GET sales from user SET list[index] to the entered sales value RETURN list DEFINE calculate_total(list): SET total to 0 FOR value in list: ADD value to total RETURN total “` submitted by /u/baliditity [link] [comments] 

I am learning python and I think I have a decent grasp in on the functionality of handling errors, however, in this mini project, I am unsure of where to handle the error. Should I handle the error in the main function or in the get_sales function, perhaps both? “` SET DAYS to 7

DEFINE main function: SET days_list to an empty list of size DAYS TRY: CALL get_sales(days_list) EXCEPT: DISPLAY “An error occurred while collecting sales data.” ELSE: SET total to calculate_total(days_list) DISPLAY “The total sales are:”, total

DEFINE get_sales(list): FOR index in range(len(list)): GET sales from user SET list[index] to the entered sales value RETURN list

DEFINE calculate_total(list): SET total to 0 FOR value in list: ADD value to total RETURN total “`

submitted by /u/baliditity
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *