PYTHON PROGRAMS

To return to the home page, click here.

COMMENTS: Since many students now use computers rather than calculators I have converted
a few of my programs to computer programs. I have chosen the Python language for reasons
which I will not try to justify.

# This program gives the largest perfect power in a number, given a number
# and a root.
#It is taken from the TI-84 program PrfPwr by F. Kizer, and rewritten 11/23/14

#Program Name: PerfPwr.py 061716
import
math
N=float(input('Enter a number: '))
R=float(input('Enter a root: '))
s=math.floor(N**(1/R))                       #Finds largest possible square
for i in range (s, 0,-1):
if (N/i**R)==math.floor(N/i**R):         #ck to see if root = root truncated.
b=N/i**R
break                                                         #Gets out of loop when 1st sq detected
print ("Factored Number: ")
print (i**R, '*', b)                                      #Enters the factored number
print ("root of", i**R, "= ", i)                   #Prints root of perf pwr

This program solves for the roots of a quadratic.

#This file calculates the roots of a quadratic.
#QuadSlv.py 061716
a=float(input ('Enter the Coeff of x Squared: '))
b=float(input ('Enter the Coeff of x: '))
c=float(input ('Enter the Constant: '))
x1=(-b+(b**2-4*a*c)**(1/2))/(2*a)
x2=(-b-(b**2-4*a*c)**(1/2))/(2*a)
print ("x1=", x1)                                           # Imaginary is indicated by j.
print ("x2=", x2)