0% found this document useful (0 votes)
22 views3 pages

U2 SB1 84python Teacher

Uploaded by

ANTATOMIC
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)
22 views3 pages

U2 SB1 84python Teacher

Uploaded by

ANTATOMIC
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/ 3

10 Minutes of Code: Python UNIT 2: SKILL BUILDER 1

TI-84 PLUS CE PYTHON TEACHER NOTES


Unit 2: Input, Output and Functions Skill Builder 1: A Tale of Two Means

In this lesson, you will write a program that requires a mathematical Objectives:
function that is not part of Python’s “built-in” tools. • Use import for additional functions
• Write a program using the menus
• Examine a mathematical relationship
1. The arithmetic mean (average, pronounced “arithMETIC” of two
numbers is:

The geometric mean is:

Write a program to calculate and display both means to compare them


for several examples.

Begin a new Python program and name it TWOMEANS.

Teacher Tip: Pronunciation matters — arithmetic (adjective), not arithmetic (noun).

Example 1: The altitude to the hypotenuse of a right triangle is the geometric mean of the
two segments on the hypotenuse.

Example 2: In an arithmetic sequence, each term after the first one is the arithmetic mean
of its two neighbors. In a geometric sequence each term after the first one is the geometric
mean of its two neighbors.

gm <= am

2. Start a line with the # sign (“pound,” “number” or “hashtag”) found on


<a A #>. Highlight the symbol, press [enter] and select <Paste>. This
symbol is used for making a #comment which is ignored when the
program runs. After the # sign, write a sentence explaining the purpose
of the program. Comments are useful in two ways:
a. They allow the programmer to document the purpose for different
chunks of code. This makes longer programs easier to read and
debug if there are errors.
b. They are useful in debugging because you can “comment out” a line
so it does not execute when the code runs. That allows the
programmer to systematically isolate where the error occurs.
Note the wraparound feature in the Editor: The remaining part of the line
is also indented a bit.

©2021 Texas Instruments Incorporated 1 education.ti.com


10 Minutes of Code: Python UNIT 2: SKILL BUILDER 1

TI-84 PLUS CE PYTHON TEACHER NOTES

3. This program requires the square root function which is not part of
Python’s built-in operations. The square root (sqrt) and other
mathematics functions are found in the standard Python module called
math. To use this function, you must import the math module to your
code. Select <Fns…> Modul > math and select the statement at the
top:
from math import *
Modules are used to keep Python small and fast: We only import stuff
that our program will actually use.

The Math menu contains lots of mathematics functions and there are
separate Const and Trig sub-menus, too. To use any of these functions
the math module must be imported into your program.

Note: The asterisk ( * ) means “from math import all.”

Teacher Tip: You can also write from math import sqrt if you know you are only going to
need the sqrt function. Or import math which requires you to write math.sqrt().
The math module, along with random and time, are standard Python modules that are
included in the TI-84 Plus CE Python system.
4. Use the input( ) function to enter the first number. First type the variable
a and the = sign ([sto] key).
Recall that input( ) returns a string and we must convert it to a number.
Combine those two steps into one by writing:
a = float(input( ))
First, get float() from <Fns…> Type,
Then, with the cursor inside the parentheses, look on <Fns…> I/O for
the input( ) function.
For the prompt inside the input( ) parentheses, write “First number?”
The question mark is on the <a A # > screen.
Write a second statement to enter the second number (not shown). This
is a good opportunity for you use the <Tools> Copy Line and Paste
Line Below features and then edit the second line.

Teacher Tip: Be careful about the two right parentheses at the end of the line: one for
input() and one for float(). This is a perfect example of “composition of functions.” The inner
function input is processed first, and the result (a string) is passed to the outer function
float.

©2021 Texas Instruments Incorporated 2 education.ti.com


10 Minutes of Code: Python UNIT 2: SKILL BUILDER 1

TI-84 PLUS CE PYTHON TEACHER NOTES

5. After your two input statements, write two assignment statements, one
for the arithmetic mean and one for the geometric mean:

am = (a + b) / 2
gm = sqrt(a * b)

sqrt() is on <Fns…> Modul math

You can also simply type sqrt( ).

6. The last task is to write the print( ) statements to display the two
calculated values. Use your imagination! A sample is shown here:

print( "am = ", am)


print( "gm = ", gm)

7. Run the program and enter two numbers for which you know the
answers… TEST, TEST, TEST.

To rerun the last program, select <tools> and press [enter].

After trying many examples, do you notice a relationship between the


two means? Is one always larger than the other? Are they ever equal?
How are they related to the two numbers you enter? Are there any
values which cause an error?

Check your guesses with the teacher! Can you prove it?

Teacher Tip:
am >= gm (When is there equality?)
am and gm are always between a and b.

The am formula works for all real numbers (complex, too).


The gm formula only works for positive numbers.

©2021 Texas Instruments Incorporated 3 education.ti.com

You might also like