In: Computer Science
(PYTHON)Your company prints math reference tables for high school and first year college students. You’d like to write a flexible program that will display the results for several mathematical functions applied to a range of integers, and the results displayed in a table with a header that includes labels separated by tabs:
Num Sqr SqRt Sin Cos Tan Log Log10
=== === ==== === === === === =====
Write a Python program that prompts the user for a starting integer, ending integer and interval (step) value. Based on these entries, and using functions from the Python math library, calculate and display each integer (x) along with the values for: x2, sin x, cos x, tan x, log(x) and log10x .
Organize your file using comments for each block of planned code
Import the math library and initialize any necessary variables
Prompt the user for the starting, ending and interval values (integers)
Print the table headers
Create a loop based on the user’s values
Print the formatted values with 2 decimal places
There are four (4) parts to this program: 1. Import math library
and initialize any necessary variables 2. Prompt the user for
starting, ending and interval values 3. Create a for loop based on
the values 4. Print each value and the calculated results as
specified
Using the IDLE Python editor, enter the following comments in your
Python program identifying each part. Make sure to leave blank
spaces between each comment section.
# Initialize any necessary variables
# Prompt the user for the starting, ending and interval
values
# Create a for loop based on the values
# Print each value and the calculated results as specified
Some hints and guidelines: • For the sin, cos and tan calculations, assume the user is providing values in degrees • The Python math library functions for sin, cos and tan expect a value in radians • Use the starting, ending and interval values to define your for loop • Round the results of the math calculations to 2 decimal places if necessary
compute.py-------
from math import * #importing math library
startingValue=int(input("Enter starting value : "))#taking
starting value from user
endingValue=int(input("Enter ending value : "))#taking ending value
from user
intervalValue=int(input("Enter interval value : "))#taking value
from user
#table for x2
print('='*40,"\n\tx2")
print('='*40)
for i in range(startingValue,endingValue+1,intervalValue):
print("\t",i,"\t->\t",i*i)#calculating x2
print()
print('*'*40)
print("\n\n")
#table for sin(x)
print('='*40,"\n\tsin(x)")
print('='*40)
for i in range(startingValue,endingValue+1,intervalValue):
print("\t",i,"\t->\t%.2f" %sin(i*(pi/180)))#x in degree is
converted to redain before calling sin(x) math library
function
print()
print('*'*40)
print("\n\n")
#table for cos(x)
print('='*40,"\n\tcos(x)")
print('='*40)
for i in range(startingValue,endingValue+1,intervalValue):
print("\t",i,"\t->\t%.2f" %cos(i*(pi/180)))#x in degree is
converted to redain before calling cos(x) math library
function
print()
print('*'*40)
print("\n\n")
#table for tan(x)
print('='*40,"\n\ttan(x)")
print('='*40)
for i in range(startingValue,endingValue+1,intervalValue):
print("\t",i,"\t->\t%.2f" %tan(i*(pi/180)))#x in degree is
converted to redain before calling tan(x) math library
function
print()
print('*'*40)
print("\n\n")
#table for log(x)
print('='*40,"\n\tlog(x)")
print('='*40)
for i in range(startingValue,endingValue+1,intervalValue):
print("\t",i,"\t->\t%.2f" %log(i))#calculate log(x)
print()
print('*'*40)
print("\n\n")
#table for log10(x)
print('='*40,"\n\tlog10(x)")
print('='*40)
for i in range(startingValue,endingValue+1,intervalValue):
print("\t",i,"\t->\t%.2f" %log10(i))#calculate log10(x)
print()
print('*'*40)
print("\n\n")
#this code is in python 3