Python For The Ti84 Powerful Python Programs And Games For The Ti84 Plus Ce Graphing Calculator Practical And Fun Python Programming For Calculators John Craig download
Python For The Ti84 Powerful Python Programs And Games For The Ti84 Plus Ce Graphing Calculator Practical And Fun Python Programming For Calculators John Craig download
Python For The Nspire Powerful Python Programs And Games For The
Tinspire Tm Cx Ii Technology Calculator Craig
https://ebookbell.com/product/python-for-the-nspire-powerful-python-
programs-and-games-for-the-tinspire-tm-cx-ii-technology-calculator-
craig-34389970
Python For The Life Sciences A Gentle Introduction To Python For Life
Scientists Alexander Lancaster Gordon Webster
https://ebookbell.com/product/python-for-the-life-sciences-a-gentle-
introduction-to-python-for-life-scientists-alexander-lancaster-gordon-
webster-36155304
Python For The Life Sciences A Gentle Introduction To Python For Life
Scientists 1st Edition Alexander Lancaster
https://ebookbell.com/product/python-for-the-life-sciences-a-gentle-
introduction-to-python-for-life-scientists-1st-edition-alexander-
lancaster-43425662
Python For Data Science The Latest Guide For The Novice Data Scientist
Learn The Principles Of Python Language To Analyze And Manage Data
Machine Learning And Scikitlearn Sections Included William Dimick
https://ebookbell.com/product/python-for-data-science-the-latest-
guide-for-the-novice-data-scientist-learn-the-principles-of-python-
language-to-analyze-and-manage-data-machine-learning-and-scikitlearn-
sections-included-william-dimick-232316884
Essential Python For The Physicist 1st Edition Giovanni Moruzzi
https://ebookbell.com/product/essential-python-for-the-physicist-1st-
edition-giovanni-moruzzi-11109812
Python For Beginners A Practical Guide For The People Who Want To
Learn Python The Right And Simple Way John Snowden
https://ebookbell.com/product/python-for-beginners-a-practical-guide-
for-the-people-who-want-to-learn-python-the-right-and-simple-way-john-
snowden-22487584
Python For Casio Calculators Powerful Python Programs And Games For
The Casio Fxcg50 And Fx9750giii Calculators Craig
https://ebookbell.com/product/python-for-casio-calculators-powerful-
python-programs-and-games-for-the-casio-fxcg50-and-fx9750giii-
calculators-craig-46317172
https://ebookbell.com/product/dead-simple-python-idiomatic-python-for-
the-impatient-programmer-converted-jason-c-mcdonald-46507694
https://ebookbell.com/product/numerical-methods-with-python-for-the-
sciences-william-miles-49178872
Python for the TI-84
Powerful Python
programs and games
for the TI-84 Plus CE Python graphing calculator
by
Acknowledgements
Introduction
Programs
1. Calendar Functions
CALENDAR
DATE
DATEPLUS
DAYSDATS
JULIAN
2. Electronics
AVGPKRMS
BRIDGE
DELTAWYE
FREQWAVE
LED_RES
OHMSLAW
PARALLEL
RCTIMING
SERIES
ZROUND
DECKCRDS
DICE
DIGITS
FACTCBPM
HEADSROW
HUNT_DIR
HUNT_DIS
JUMBLE
MAZE
MEMORY
MNTYHALL
PI_BUFFN
PI_DARTS
RNDMBYTE
WORDPERM
GPS_AREA
GPS_DIST
MIDPOINT
NAVIGATE
DEPOSITS
FUTURVAL
INTEREST
MONTHS
PAYMENTS
PRNCIPAL
6. Numerical Calculations
BINHXDEC
BINSRCH
FACTORS
FIBONACC
GCD_LCM
GLDRATIO
NEWTON
PRIMES
QUADRATC
REC_POLR
SIMULTEQ
VECTORS
CONCRETE
CRICKETS
LASERDIS
MPH
SECRET
WAIT_KEY
WET_BULB
WNDCHILL
8. Plane Geometry
ARCS
AREA_3P
AREA_3S
AREA_PTS
CIRCLE3P
DISTANCE
DIVLINE
LINE_2P
LINSLOPE
TRANSFRM
TRIANG3P
TRIANGLE
9. Space Geometry
COORD_3D
DIVLIN3D
ROTATE3D
TRIANG3D
VOLUME4P
Why Python?
Python handles number crunching well, and with its lists, strings, and
other data structures, it powerfully handles a very wide variety of
programming tasks. But perhaps the biggest advantage of learning Python via
your programmable calculator is that this knowledge will be applicable and
useful no matter what computers or systems you might work with in the
future. Learn it once and you'll have a new life skill of great value.
def add(x,y):
return x+y
After you run this program, in the shell you can type something like
"add(3,4)" to get 7, or to add any two numbers or variables together. Or,
rather than type the function names yourself, on your TI-84 CE Plus Python
calculator, you can select "4:vars..." from the [Tools] menu to access a quick
list of functions your program has defined. More complicated functions can
add some powerful new capabilities to your computation toolbox!
There are a few other useful I/O tricks presented in several of the
programs in this book. It is sometimes useful to ask for a number, but to let
the user simply press [enter] without entering a number if they don't know the
value. This is actually a tricky thing to do, as a simple assignment to a
variable after an input() function call can fail if nothing is input. Take a close
look at the program ARCS, in chapter 8 for an example where any
combination of two of four variables can be entered, and the missing ones
will be calculated. Here's a pair of code lines where an angle is entered, or a
value of zero is put in place if the user simply presses [enter].
There are many, many resources online and in other books to learn the
intricacies of the Python language. The goal of this book isn't to duplicate all
this information. Instead, there's a lot of short, useful programs that you can
use "right out of the box", and in putting them to use you'll learn a lot about
Python indirectly.
If you are looking for an absolute beginner's tutorial to help you get up to
speed with programming in Python on your TI-84 Plus CE Python calculator,
there's an excellent web site by Texas Instruments titled "10 Minutes of
Code: Python". I strongly recommend taking a look at these skill building
lessons. Here is the link:
https://education.ti.com/en/activities/ti-codes/python/84
Any TI-84 calculator is a very powerful learning tool, but with the
addition of Python in your TI-84 Plus CE Python calculator, its mind-
expanding capabilities are truly awesome!
1.
Calendar Functions
Next time someone asks you this question, you can answer with the exact
number of days rather than just rounding off to the number of years. Then, to
impress them even more, be sure to casually mention the day of the week you
were born.
These are the types of questions the programs in this chapter will let you
answer with ease.
CALENDAR
At the heart of this program is a function that returns the Julian Day
Number for any date in the range of years from 1582 to 4000. This function,
named jd(), is explained in more detail later in this chapter, but here it is used
to determine the number of days in any given month, and the day of the week
for any date. From this information we can format all the days in a given
month into an easy-to-read one-month calendar.
Wilbur and Orville Wright's first heavier than air flight took place on the
morning of December 17, 1903, at Kitty Hawk, North Carolina. We can run
this program to see the full one-month layout of December, 1903 and easily
determine that the 17th was a Thursday.
import ti_plotlib as plt
def jd(m,d,y):
if m<3:
y-=1
m+=12
a=int(y/100)
b=2-a+int(a/4)
e=int(365.25*(y+4716))
f=int(30.6001*(m+1))
return b+d+e+f-1524.5
This program uses the Julian Day Number function to calculate the day of
the week and the day of the year for a date in the range of years from 1582 to
4000. The jd() function is described in more detail elsewhere in this chapter.
For example, December 17, 1903 (the day Orville and Wilbur made their
first heavier-than-air flight) was a Thursday, and it was the 351st day of the
year, as shown in the following output in the Python Shell..
The day of the year is found by subtracting the Julian Day Number for
December 31 of the previous year from the selected day's Julian Day
Number.
def jd(m,d,y):
if m<3:
y-=1
m+=12
a=int(y/100)
b=2-a+int(a/4)
e=int(365.25*(y+4716))
f=int(30.6001*(m+1))
return b+d+e+f-1524.5
In case you're wondering, yes you can add a negative number of days to
find an earlier date.
To perform this calculation the starting date is converted to its Julian Day
Number using the jd() function, the number of days is added to create a
second Julian Day Number, and the mdy() function converts that number
back to a date. The Julian Day Number automatically takes care of leap years,
varying numbers of days in the months, and all those details. These two
functions are described in more detail in the julian.py program in this chapter.
from math import *
def jd(m,d,y):
if m<3:
y-=1
m+=12
a=int(y/100)
b=2-a+int(a/4)
e=int(365.25*(y+4716))
f=int(30.6001*(m+1))
return b+d+e+f-1524.5
def mdy(jd):
z=int(jd+.5)
f=jd+.5-z
if z<2299161:
a=z
else:
t=int((z-1867216.25)/36524.25)
a=z+1+t-int(t/4)
b=a+1524
c=int((b-122.1)/365.25)
g=int(365.25*c)
e=int((b-g)/30.6001)
d=int(b-g-int(30.6001*e)+f)
if e<14:
m=e-1
else:
m=e-13
if m>2:
y=c-4716
else:
y=c-4715
return [m,d,y]
How many days will you have been on the Earth on your next birthday?
This kind of question is easy to answer with this program. Two dates are
input, they are converted to Julian Day Numbers, and the difference between
them is output as the number of days between the two dates.
The sample calculation finds the number of days from the day Orville and
Wilbur made their first flight ( December 17, 1903) and the date of Y2K, or
January 1, 2000. The result is 35,079 days to be exact.
def jd(m,d,y):
if m<3:
y-=1
m+=12
a=int(y/100)
b=2-a+int(a/4)
e=int(365.25*(y+4716))
f=int(30.6001*(m+1))
return b+d+e+f-1524.5
print("\nFirst date")
m1=int(input("Month (1-12): "))
d1=int(input("Day (1-31): "))
y1=int(input("Year (1582-4000): "))
print("\nSecond date")
m2=int(input("Month (1-12): "))
d2=int(input("Day (1-31): "))
y2=int(input("Year (1582-4000): "))
nd=int(abs(jd(m1,d1,y1)-jd(m2,d2,y2)))
print("\n{}/{}/{}".format(m1,d1,y1))
print("{}/{}/{}".format(m2,d2,y2))
print("Days between: ",nd)
JULIAN
This program demonstrates two functions that are very useful for a
variety of calendar calculations. All other programs in this chapter use one or
both of these functions.
jd() calculates the Julian Day Number for a given date in the year range
1582 to 4000. This is an absolute day number used by astronomers and others
to clearly designate the sequence for each day, without regard to leap years
and other such complications.
Note that for historical reasons, each astronomical day begins at noon
Greenwich time, so there's an extra ".5" on these Julian Day Numbers. In the
programs presented here we add and subtract whole days to find relative
dates, and this extra fractional part doesn't really matter. For astronomical
calculations this fractional part does become important.
The mdy() function provides a way to convert a Julian Day Number back
to a triplet of numbers for the month, day, and year for that date. This makes
it easy to add and subtract days to get a new date accurately, without having
to do any complicated adjustments for the number of days in each month, or
for leap years.
The example code inputs a date and outputs its Julian Day Number. Next,
any Julian Day Number is input and the calendar date for that day is output.
As shown, December 17, 1903 has Julian Day Number 2,416,465.5 and
Julian Day Number 2,500,000.5 will fall on September 1 in the year 2132.
from math import *
def jd(m,d,y):
if m<3:
y-=1
m+=12
a=int(y/100)
b=2-a+int(a/4)
e=int(365.25*(y+4716))
f=int(30.6001*(m+1))
return b+d+e+f-1524.5
def mdy(jd):
z=int(jd+.5)
f=jd+.5-z
if z<2299161:
a=z
else:
t=int((z-1867216.25)/36524.25)
a=z+1+t-int(t/4)
b=a+1524
c=int((b-122.1)/365.25)
g=int(365.25*c)
e=int((b-g)/30.6001)
d=int(b-g-int(30.6001*e)+f)
if e<14:
m=e-1
else:
m=e-13
if m>2:
y=c-4716
else:
y=c-4715
return [m,d,y]
Homes in the United States are supplied with electrical power in the form
of a sine wave with an effective voltage of about 117 volts. This effective
voltage provides the same power in watts to a resistive load as would a DC
voltage of 117 volts. Effective voltage is also called RMS, which stands for
"Root-Mean-Squared", because of the way it is mathematically derived.
Most of the time we use the effective voltage value, because it is the
value that allows quick calculation of power to a circuit. But there are two
other ways to measure a sine wave voltage. The peak voltage, at the very top
point of the sine wave, provides a "Peak" voltage value, and the average
magnitude of the voltage over time, without regard to polarity, provides the
"Average" voltage value.
Here are the two main conversion equations. All the relationships
between Peak, Average, and RMS voltages can be figured out by
algebraically working with these two:
As shown in this sample run, a standard U.S. house wiring voltage of 117
V (RMS) has a peak voltage of about 165 V, and an average voltage over
time of about 105 V.
def ac_voltages(avg,peak,rms):
if avg:
peak=pi*avg/2
rms=peak/sqrt(2)
elif peak:
avg=peak*2/pi
rms=peak/sqrt(2)
elif rms:
peak=rms*sqrt(2)
avg=peak*2/pi
return [avg,peak,rms]
The following example calculates the value of the 4th leg resistance when
the first three resistors are 2700, 3900, and 5600 ohms, and it solves a second
time for complex impedances of 4+3j, 5+0j, and 3-7j.
As shown, the 4th resistor in the first case should be approximately 3877
ohms, and the impedance in the second case should be 6.6-3.8j ohms.
def bridge(z1,z2,z3):
return z1*z3/z2
r1=2700
r2=3900 # opposite the unknown
r3=5600
r4=bridge(r1,r2,r3)
print("r1: ",r1)
print("r2: ",r2)
print("r3: ",r3)
print("bridge(r1,r2,r3): ",r4)
z1=4+3j
z2=5+0j # opposite the unknown
z3=3-7j
z4=bridge(z1,z2,z3)
print("z1: ",z1)
print("z2: ",z2)
print("z3: ",z3)
print("bridge(z1,z2,z3): ",z4)
The bridge() function is very small, just the first two lines of code. Most
of this program demonstrates calling the bridge() function twice, once to
solve for a pure resistive bridge, and a second time to balance a bridge
composed of complex value impedances.
DELTAWYE
When you run this program, nothing happens. Okay, a little explanation
is in order. As explained early in this book, a simple and straightforward way
to add powerful functions to your calculator is to simply define functions in a
program that you can use over and over while working on some relevant
problems. In this case, two functions are defined at run time, delta() and
wye(), and they remain in the shell ready for your use.
You can type in these functions along with the parentheses that follow
them, but a nice quick way to access them is to choose 4:Vars from the Tools
menu. Choose a function from the list that shows, then you'll be able to type
in its parameters.
The delta configuration is called that because the three resistors are
arranged in a triangle, although circuit diagrams often show them in more of
a pi arrangement, as shown here on the left. Notice that if you "pull together"
the bottoms of RB and RC, a triangle, or "delta" is formed.
The delta() function uses the following equations to find values for RA,
RB, and RC that form an equivalent set of resistances, or impedances, when
given R1, R2, and R3.
The wye() function uses the following equations to find values for R1,
R2, and R3 that form an equivalent set of resistances, or impedances, when
given RA, RB, and RC.
The first few lines of code in the program define these delta() and wye()
functions. I've added optional print() commands at the end of the listing to
remind you at runtime how to call each of them. This is a good way to self-
document functions that are defined, but not actually called at runtime.
def delta(z1,z2,z3):
tmp=z1*z2+z2*z3+z3*z1
return tmp/z1,tmp/z2,tmp/z3
def wye(za,zb,zc):
tmp=za+zb+zc
return zb*zc/tmp,za*zc/tmp,za*zb/tmp
Here's the result of calling each function. In the first case we convert
resistances in a wye configuration of 300, 400, and 500 ohms to the
equivalent delta configuration. The result is about 1567, 1175, and 940 ohms.
The second call converts impedances of 4+3j, 5, and 3-7j ohms from a delta
configuration to equivalent wye values. The results are the complex values 2-
2.25j, 2.95-0.6j, and 1.125+1.625j ohms.
FREQWAVE
Frequency in hertz and wavelength in meters are the exact inverse of each
other. They are both a function of the speed of light. Here's the simplest
equation that ties all this together, where C is the speed of light:
def logb(x,b):
return log(x)/log(b)
def eng(x,d):
x=abs(x)
if x==0:
return "0.0"
exp=floor(logb(x,10))
mant=x/10**exp
r = round(mant,d-1)
x = r*pow(10.0,exp)
p = int(floor(logb(x,10)))
p3 = p//3
value=x/pow(10.0,3*p3)
s="{:f}".format(value)
if s[d]!=".":
s=s[0:d+1]
else:
s=s[0:d]
if p3!=0:
return "{}e{:d}".format(s,3*p3)
else:
return "{}".format(s)
c,f,w=299792458,0,0
print("\nEnter known value...")
f=input("Frequency: ")
f=float(f) if f else 0
if f==0:
w=input("Wavelength (m): ")
w=float(w) if w else 0
if w!=0:
f=c/w
if f!=0:
w=c/f
digits=5
print("\nFrequency:")
print("{} Hz".format(eng(f,digits)))
print("\nWavelength:")
print("{} meters".format(eng(w,digits)))
This program prompts for a frequency, then for a wavelength if you skip
frequency by pressing [enter] without entering a number. The unknown value
in either case is calculated, both values are formatted into engineering
notation, and the results are output to your calculator's display.
Two example runs are shown, the first where a frequency is the known,
and second where a wavelength is the known value. In the first example the
frequency of the Helium "People's Network" for the Internet of Things (IOT)
is entered to calculate its wavelength. 915 megahertz has a wavelength of a
little less than a third of a meter.
In this second example we skip the frequency input and then enter 5 to
calculate the frequency when the wavelength is exactly 5 meters. The
frequency is just a tad less than 60 megahertz.
Note that the variable named digits, near the end of the program, is set to
five. Change this value if you want higher or lower precision in your answers.
For easy reference, here's a list of the metric prefixes for the various
engineering notation powers of ten:
LED_RES
LEDs are awesome. Once you know how to power them properly, you
can light up all kinds of fun artwork, gadgets, and inventions in any color and
blinking patterns imaginable. For example, the author invented a brake light
for bicycles that requires no wiring to the brakes at all, instead relying on an
accelerometer chip to determine when to flash bright red LEDs to indicate
deceleration. Check out LucidBrakes online.
def led_resistor(Vs,Vf,i):
r=(Vs-Vf)/i
Rw=(Vs-Vf)*i
Lw=Vf*i
return [r,Rw,Lw]
def led_current(Vs,Vf,r):
i=(Vs-Vf)/r
Rw=(Vs-Vf)*i
Lw=Vf*i
return [i,Rw,Lw]
The following two example runs first find the approximate value for a
resistor when the current is known, and the second example calculates the
current when a standard resistor is selected for the circuit.
In both cases you enter the source voltage and the LED forward voltage
(this Vf varies for LED types), and then enter either the current in amps or the
resistor value in ohms.
For a circuit powered with 12 volts, an LED with a forward voltage drop
of 2.4 volts with 25 mA of current through it requires an approximate resistor
size of 384 ohms.
The next run, with a voltage source of 9 volts and an LED forward
voltage drop of 2.3 volts and a standard resistor value of 270 ohms, results in
a current of about 24.8 milliamps.
It's important not to burn out the resistor or the LED in your circuit.
Resistors have a stated wattage, and they'll be okay if Wres is less than this
value. In our example the resistor is heated with about 0.17 watts of power,
so a standard quarter watt (0.25 watts) resistor should work fine. LEDs have a
stated maximum current, which you can also check with these results.
OHMSLAW
You can type the names of the functions, or you can select them from the
Tools menu through the 4:Vars option.
def ohms_law(p,i,e,r):
if p and i:
e=p/i
r=p/(i*i)
elif p and e:
i=p/e
r=(e*e)/p
elif p and r:
i=math.sqrt(p/r)
e=math.sqrt(p*r)
elif i and e:
p=i*e
r=e/i
elif i and r:
p=i*i*r
e=i*r
elif e and r:
p=(e*e)/r
i=e/r
else:
pass
return ([p,i,e,r])
print("\nohms_law(p,i,e,r)")
print("Pass two known values, and zeros")
print("for the other two unknowns.")
PARALLEL
Here's a sketch showing how the multiple resistors are wired in parallel:
The program defines a function named parallel(), and prints two lines of
instructions. Note that a single list of values is passed to this function,
allowing any number of parallel resistances or impedances to be processed.
Just add two or more to the list and pass the list to this function. The example
shows how square brackets define a list.
def parallel(zlist):
zp=sum(1/z for z in zlist)
return 1/zp
Random documents with unrelated
content Scribd suggests to you:
Ga g a ,
From where the West yet kept a pallid star
To thinner sky where dawn was wearing through,
Hugh shrank with dread, reluctant to renew
The war with that serene antagonist.
More fearsome than a smashing iron fist
Seemed that vast negativity of might;
Until the frustrate vision of the night
Came moonwise on the gloom of his despair.
And lo, the foe was naught but yielding air,
A vacancy to fill with his intent!
So from his spacious bed he ‘rose and went
Three-footed; and the vision goaded him.
S bi t l d i
Succumbing to a languorous despair,
He mourned his fate with childish uncontrol
And nursed that deadly adder of the soul,
Self-pity. Let the crows swoop down and feed,
Aye, batten on a thing that died of need,
A poor old wretch betrayed of God and Man!
So peevishly his broken musing ran,
Till, glutted with the luxury of woe,
He turned to see the butte, that he might know
How little all his striving could avail
Against ill-luck. And lo, a finger-nail,
At arm-length held, could blot it out of space!
A goading purpose and a creeping pace
Had dwarfed the Titan in a haze of blue!
And suddenly new power came to Hugh
With gazing on his masterpiece of will.
So fare the wise on Pisgah.
ebookbell.com