#!/usr/bin/python3 # -*- coding: UTF-8 -*- # filename: port_of_second_program.py # rev. date/time: 03-30-13-0834 hrs. # by Mr. Cantlin. # Line 1 above is traditionally called a "shebang" line in Python. # The #! symbols are the reason for the name. # The # does not start a comment line in this first line. # There should be no white space in the shebang line. # The shebang tells the OS where to find the Python files. # /usr/bin/python3 is where Python is installed # on the Bulldogmath server. # It is not needed when you are running programs from IDLE. # **************************************************** # A pair of vectors below to use for testing. See Ex. 3 Pg. 230 # Vector 1 = (13.8, 40.2 degrees) # Vector 2 = (20.9, 164.6 degrees) # Resultant Vector - Rectangular Form = (-9.6, 14.5) # Resultant Vector - Polar Form = (17.4, 123.6 degrees) # All text references are from "Trigonometry with Applications" # By Wesner and Mahler, 3rd Ed. 1994, ISBN 0-697-12292-1 # **************************************************** # ************************************************************** # Install CGI support and math support. # The Python script is run as a CGI program. # CGI=Common Gateway Interface, used for many scripting languages. # Most Linux servers have a /cgi-bin/ folder for these programs. # This .py program will be changed to .cgi program to run. # The Python interpreter on the server is smart enough to # still know it is a Python program. Prob. from the shebang line. # Python needs to install several CGI realted modules. # ************************************************************** # ************************************************************** # Intall modules Python needs for this program. Don't forget "math". import math import cgi import cgitb cgitb.enable() # enable debugging # ************************************************************** # ************************************************************** # Define and initialize all variables # Use 0.0 to define as Floating Point. "anything" to define as strings. # The input received from the hlml form will be as strings (_s added to these.. vector1_magnitude = 0.0 vector1_angle = 0.0 vector2_magnitude = 0.0 vector2_angle = 0.0 vector1_magnitude_s = "input_string" vector1_angle_s = "input_string" vector2_magnitude_s = "input_string" vector2_angle_s = "input_string" vector1_x = 0.0 vector1_y = 0.0 vector2_x = 0.0 vector2_y = 0.0 vector_sum_x = 0.0 vector_sum_y = 0.0 vector_sum_magnitude = 0.0 vector_sum_angle = 0.0 # ************************************************************** # ************************************************************** # Print to HTML requires this setup - it has THREE sections. # Section 1: Two Lines Separate this from Section 2 with blank line print("Content-Type: text/html") # HTML is following print() # blank line, end of headers # ************************************************************** # ************************************************************** # Section 2: Start Main HTML Output i.e. html framework print("
") print("Vector 1 Magnitude:", vector1_magnitude,"
")
print("Vector 1 Angle:", vector1_angle, " degrees")
print("
Vector 2 Magnitude:", vector2_magnitude,"
")
print("Vector 2 Angle:", vector2_angle, " degrees")
print("
Vector Sum in Rectangular Form: ","(",vector_sum_x,",",vector_sum_y,")") print("
Vector Sum in Polar Form: ","(",vector_sum_magnitude,",",vector_sum_angle,"degrees",")","") # ************************************************************** # ************************************************************** # Section 3: End Main HTML Output i.e. html framework # End of the HTML section. print ("")