You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement error handling using the decision block and catch statement. This feature will also require implementing a core library named errors to fetch the error code. The syntax will look like this:
fromerrorsimportindex_out_of_rangenumdefreturn_zero()numr=0retunrendnumdefreturn_first(numlista)numr=a[0]retunrend{catchindex_out_of_range() : return_zero()}numdefget_index_of_using_sum(numlista,numx,numy)numz=x + ynumr=a[z]returnrend{catchindex_out_of_range() : return_first(a)}printget_index_of_using_sum([1,2,3,4,5],1,4)# Should print 1printget_index_of_using_sum([],1,1)# Should print 0
In that way, one can implement his/her own function to return the desired error code instead of using the errors library:
numdefindex_out_of_range()numr=8returnrendnumdefreturn_zero()numr=0retunrendnumdefreturn_first(numlista)numr=a[0]retunrend{catchindex_out_of_range() : return_zero()}numdefget_index_of_using_sum(numlista,numx,numy)numz=x + ynumr=a[z]returnrend{catchindex_out_of_range() : return_first(a)}printget_index_of_using_sum([1,2,3,4,5],1,4)# Should print 1printget_index_of_using_sum([],1,1)# Should print 0
The text was updated successfully, but these errors were encountered:
Implement error handling using the decision block and
catch
statement. This feature will also require implementing a core library namederrors
to fetch the error code. The syntax will look like this:In that way, one can implement his/her own function to return the desired error code instead of using the
errors
library:The text was updated successfully, but these errors were encountered: