Some frequently asked questions about Program 1
Yes, you have to put in a main function, just like all
the code you have seen in class.
All your code goes inside the main function.
NO variables or code go outside the main function definition.
- On the other hand, the import statement for any library you
need is the exception - it MUST go before the def main line.
The header documentation is described in the programming standard:
Name, section, email address, date,
purpose, pre-conditions (what the program expects as inputs), post-conditions (what the program produces)
- Your design steps go in between the Python code statements.
- Try as closely as possible to match prompts and labels, line breaks, indentations, etc.
that are given in the sample runs.
- Good variable names describe their own purpose.
Use blank lines and spaces around operators in your code to make it easier to
read - bunched up blocks of text are not really inviting to read.
Keep the length of your lines around 80 or 100 characters
(the red line in the WingIDE editor is a good guide).
You can break about anything in Python across lines except a
string constant ("long line" would have to be on one line).
If a carriage return (line break) gives you trouble, you can
always end the first line with the \ symbol. This allows you
to continue statements to the next line.
The round function should be used to control the number of
decimals output. Use the round function, not the int typecast, not the ceil function.
round(x) will return for you an integer with no decimal places
round(x,0) will return for you the whole number part of x with a .0 at the end.
round(x,y) will return for you the value of x, up to y decimal places,
rounded. Occasionally the round function will return fewer than y
places. This is ok.
You can use the round function either in the assignment statement where
you calculate the equations, or in the output statement where you output the results.
x = round(y + z,3)
print(round(y + z), 3)