0% found this document useful (0 votes)
7 views1 page

INTRO PYTHON - Prac Test

bbbuebuber

Uploaded by

komronab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

INTRO PYTHON - Prac Test

bbbuebuber

Uploaded by

komronab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Willetton SHS Python Introduction – Practical Test

Python Introduction – Practical Test NAME:

Write Python code to address the following task as fully and accurately as possible.
Read ALL the instructions below BEFORE beginning!

The hypotenuse of a right-angle triangle abc is the longest side (c) and is opposite the right angle.
(See diagrams below)

c
b

a
You are required to write a modular program in python that:
1. displays the program title “HYPOTENUSE CALCULATOR BY: your full Name” in the Python console with a
blank line above and below, where your full name are your actual real names.
2. displays a short message explaining the purpose of the program to the user.
3. requests 2 numbers from the user, sideA and sideB, representing the length of sides a and b.
(Only Positive numbers less than or equal to 100 are acceptable otherwise display an error message and
allow up to 3 tries to input valid lengths for the sides, before the program quits.)
4. outputs the result of calculating the hypotenuse of a right triangle with side lengths a and b, using the
following sentence
“The hypotenuse of a right triangle with Side A of length ______ and Side B of length ______ is _______”
The actual values input for a and b and the calculated value of the hypotenuse c should replace the
underscores in the sentence.
5. under all circumstances, the program ends by displaying the message
“PROGRAM ENDED. THANKYOU.” With a blank line above it.

Assumptions, directions and limitations:


1. Your python source code file must be named:
PythonPracTest_YourFullName.py
When complete, you must upload it into the appropriate CONNECT submission box for marking.
2. You must include Your full name, the python filename and the creation date in YYYYMMDD format as
comments at the top of the python source file.
3. No additional/external code libraries may be “imported” into this program
4. You must validate all user input.
5. NO Input or Output allowed from within functions! All I/O must be undertaken within the mainline.
6. You may assume that the hypotenuse of a right triangle can be calculated using the formula:
hypotenuse 𝑐 = √𝑎& + 𝑏&
7. You must define and call (execute) the following three functions:
– square(n) which returns the square of n (ie. n x n)
– sqroot(y) which returns the square root of y given this can be calculated in Python by
y ** (1/2)
ie. the square root of a number is the same as raising the number to the power of a half
– hypotenuse(a,b) which uses square(n) and sqroot(y) to return the hypotenuse where a and b are
numeric values greater than 0 and less than or equal to 100

Page 1 of 1

You might also like