Write a python program to print a table of sine and cos functions for the interval from 0-360 degrees in increments of 15.
please I want answer
Answers
Answered by
14
The given problem is solved using language - Python.
from math import sin,cos,radians
from tabulate import tabulate
headers=[
'Angle (x)', 'sin(x)','cos(x)'
]
list=list()
for i in range(0,360+1,15):
x=[]
x.append(str(i)+chr(176))
x.append(round(sin(radians(i)),2))
x.append(round(cos(radians(i)),2))
list.append(x)
table=tabulate(
list,
headers=headers,
tablefmt='grid'
)
print(table)
- Here, I have used tabulate module to display the data in tabular format.
- sin() and cos() function calculates the sin and cos of angle in radians.
- So, we need to convert angles to radians.
- After conversions, we are storing the data in a list.
- The list is then displayed in tabular format.
See attachment for output.
Attachments:
Similar questions