In the context of this exercise that introduces comments, where should comments be added to the code? Can I just add comments to every line of code to be safe?
Generally, comments should only be added to pieces of code that would not be obvious to others who are reading it. Adding comments to every line of code is usually not necessary, and having too much text in a file can overcrowd it, ultimately making it harder to work with or understand.
Comments help provide context for why a particular piece of code was written in that way, and also help others understand the code itself faster. Comments are typically added above the code they are describing.
# When hitpoints are below 5% and shields are gone, self-destruct. if hp < 5 and shields == False: self_destruct()