stoplight[key'yellowelif stoplight[key='yellow'stoplight[key'redelif stoplight[key='red'stoplight[key'greenswitchlights(market_ ndyou may already see the problem with this codebut let' pretend you wrote the rest of the simulation codethousands of lines longwithout noticing it when you finally do run the simulationthe program doesn' crash--but your virtual cars dosince you've already written the rest of the programyou have no idea where the bug could be maybe it' in the code simulating the cars or in the code simulating the virtual drivers it could take hours to trace the bug back to the switchlights(function but if while writing switchlights(you had added an assertion to check that at least one of the lights is always redyou might have included the following at the bottom of the functionassert 'redin stoplight values()'neither light is redstr(stoplightwith this assertion in placeyour program would crash with this error messagetraceback (most recent call last)file "carsim py"line in switchlights(market_ ndfile "carsim py"line in switchlights assert 'redin stoplight values()'neither light is redstr(stoplightassertionerrorneither light is red{'ns''yellow''ew''green'the important line here is the assertionerror while your program crashing is not idealit immediately points out that sanity check failedneither direction of traffic has red lightmeaning that traffic could be going both ways by failing fast early in the program' executionyou can save yourself lot of future debugging effort logging if you've ever put print(statement in your code to output some variable' value while your program is runningyou've used form of logging to debug your code logging is great way to understand what' happening in your program and in what order it' happening python' logging module makes it easy to create record of custom messages that you write these log messages will describe when the program execution has reached the logging debugging