Programming Assignment Unit 2
Programming Assignment Unit 2
The area of a triangle is given by the formula Area = 1/2 * Base * Height. Using the IDLE development
environment, create a Python script named t_area . Your script must calculate the area of a triangle and display
the results of the calculation. The triangle that your script must calculate the areas for has a base of 12 inches
and a height of 16 inches. IDLE has both an interactive mode and a script mode. You must use the script mode
to develop your script.
Your script must use (at a minimum) the following three variable names.
area - this variable will contain the results of the calculation which will be the area of the triangle.
base – this variable will contain the length of the triangle base. You must set the value of this variable to 12.
height – this variable will contain the height of the triangle. You must set the value of this variable to 16.
Your script must have at least 2 comments that describe what is happening in your script. Comments may
describe the assignment of a value to a variable, the computation of area and the assignment of the result to
the variable area, or the display of the result.
Your script must display the results of your calculation computing the area of the triangle using the print
statement. You must code your script, test it, and if required, debug it. When you have successfully completed
this assignment please capture the output displayed by your script. You can copy and paste the output from the
IDLE window into a document and attach it to your assignment.
Example:
The following shows and example python script that computes the area of a circle. The area of a circle is given
by the formula area = pi * radius squared
# assign the value 3.14 to the variable pi
pi = 3.14
# the value of pi
area = pi * (radius * radius)
To execute a script, you can select the ‘Run Module’ option under the run menu or simply press F5 on your
keyboard.
Under the options menu there is an option to configure IDLE. You can configure settings such as the font size
of text and other features using this menu.
Under the Help menu option there is both IDLE help which provides information about the features of IDLE as
well as an option that will bring up the Python documentation.
The following will be the items used in the grading rubric of this assignment. Make sure that you have
addressed each item in your assignment. You should submit the python script that you created for this
assignment (this should be a file with an extension of .py or .txt, txt is preferred). It will be easier on you and the
assessors if you upload your program file with a txt extension. You must also copy the output produced when
you execute your script and attach as part of your assignment. The output can be captured either by selecting,
copying and pasting the lines of output from the IDLE run window into a document, or you can capture (on
windows) an image of the output window by using the (Ctrl)+ (Alt)+ (Prnt Scn) key sequence to capture the
image of the screen and pasting this document into a word document. You should only attached documents in
the word format (.doc file extension). Both Microsoft Word and OpenOffice can save files in Word 97/2000
format.
This assignment has two components:
1 – the Python script file
2 – the output file
The assignment will allow you to upload multiple files.