questions
Anyone in the class edit this page. Brownie points for both good questions and good answers.
your question
... can go here.
Can I type python code into one of these wiki pages?
Where do I put the graphics.py module so that things work?
If the current folder doesn't work (or you're using an IDE, i.e. double-clicking something to run python - and can't tell what the current folder is), you can find a list of folders where python looks for things to import by doing this:
>>> import sys
>>> print sys.path # print a list of folders where I can put graphics.py
>>> import os
>>> print os.getcwd() # print the current directory
What is a "domain error", and why do I get it in this line
a = sqrt( b^2 + c^2)
A "domain error" means that you're doing something math-ish with out of range arguments, like trying to take the square root of a negative number. Here the problem is that b^2 doesn't mean "b squared", it means "b bitwise_xor 2", which is quite different, and might be negative. In python, "b squared" is written b**2.
How do loops work in doctests?
Answer: put 'em in the doctest exactly as they look from an interactive prompt:
"""
>>> for i in range(3):
... print i
...
0
1
2
"""
import doctest
doctest.testmod()
How do you use assertions? Can they go in doctest?
Answer: like this. And yes.
"""
In a doctest; success doesn't print anything.
>>> assert 1==1
"""
import doctest
doctest.testmod()
# in python code, with an (optional) failure message:
assert 1==2, "one isn't two"