Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
16 views

Programming Assignment Unit 2

The document describes a programming assignment to create a Python script that calculates the area of a triangle with a base of 12 inches and height of 16 inches. The script must use variables named 'area', 'base', and 'height' and include at least two comments. It also provides instructions on using the IDLE development environment to create, save, and run Python scripts. Students are asked to submit both their Python script file and the output displayed when running the script.

Uploaded by

Aaron Mutekulwa
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Programming Assignment Unit 2

The document describes a programming assignment to create a Python script that calculates the area of a triangle with a base of 12 inches and height of 16 inches. The script must use variables named 'area', 'base', and 'height' and include at least two comments. It also provides instructions on using the IDLE development environment to create, save, and run Python scripts. Students are asked to submit both their Python script file and the output displayed when running the script.

Uploaded by

Aaron Mutekulwa
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Programming Assignment

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

# assign the value 8 to the variable radius


radius = 8

# assign the results of the operation to the variable area


# the operation multiplies radius by radius and then multiplies the result by

# the value of pi
area = pi * (radius * radius)

# print the value of area


print(area)
Using IDLE
IDLE is a Integrated Development Environment or IDE. An IDE will enable you to use a text editor to create
programs (in the case of Python we refer to the program as a script) as well as execute the program. The IDLE
editor understands the syntax of the Python programming language and can help you to debug your program
by identifying code that is not valid and must be corrected.
When you first start IDLE, it will display a window that is the Python interpreter. You can type Python
commands directly into this environment and Python will interpret and execute them. For all of the assignments
in this course, you must create a script. To create a script, select new window from the file option. This will
open a new script file. You can also use the open or recent files options under the file menu to open files that
you have previously created.
You can enter your script into the window that opens when you use the new window option. Before executing
your script, you must save it. The first time you attempt to save a new script, you will need to give it a name. All
Python scripts must have the suffix of py or txt on the filename.

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.

You might also like