18
loading...
This website collects cookies to deliver better user experience
SyntaxError
. If you get a syntax error, look up the syntax to verify you have the right thing.python docs
and the thing I want to look up. Most of the time, one of the first results is exactly what I need. Notice, I included the language I’m working with and the word docs
.print()
()
without an equals sign =
()
with an equals sign =
()
underneath this line of code.# Repeat steps forever and ever until end of time or battery dies
# Every 1 second up to 59, add 1 to the seconds on screen then
# Add 1 to the minutes on the screen up to 59 then
# Add 1 to the hours on the screen up to 12
#
. Whenever you use a #
you’re saying the computer should ignore what comes after it. What comes after the #
is meant for humans. Typically, comments are on the line above your code or at the end of the line. It should be an explanation of the what and why of your code. Think of it as a reminder to a future you and an explanation to anyone else reading your code. Oftentimes, your pseudocode will be repurposed and used to comment your code.print(“The Henna Wars”) # output title of book
# TODO: output author of book - Adiba Jaigirdar
//
.cat_summoning_spell
. I promised I giggled when I came up with that. As fun as it can be, naming can be hard too.x
or foo
doesn’t explain what something is. Instead, you could describe what the thing is. If you’re counting stars, you could use something like star_count
, star_num
, or num_of_stars
. Having descriptive variables will help you avoid errors.SyntaxError
and a NameError
.SyntaxError
when your syntax is messed up. Verify you have it right. I promise, even if you think you have it right, verify anyway. If you’re not sure, you can always look at documentation. Oftentimes, we assume we typed something right and we made a tiny mistake.NameError
when names don’t match. For example, if you have something called dog_feet
but you later tried to use dog_paws
or dog_foot
you’ll get this NameError
.#
in front of that line so the computer will ignore that line. You’ll do this with lines that work perfectly and you know aren’t the problem. This helps narrow down the offending or broken code.python NameError: name 'cats' is not defined
. Generally the results will lead you in the right direction. You may have to look at a few different results to get the answer you need.Pseudocode Examples |
---|
first example |
another example |
and maybe another? |