Question & Answer: Using python: Write a computer code to produce a…..

Using python:

Write a computer code to produce a table with 2 columns. The first column contains x, numbers from 0, .1, .2, … , 1.2. The second column contains the cos(x) for those values. Use a “for loop” to generate the table. The cosine should show exactly 4 decimal digits(use %f format for each column). The first line(Header) should say what is in each column like ” x cos(x)”. Results should be printed to a file.

Expert Answer

 

import math
n = 1.2
i = 0.0
print(“x     cos(x)n”)
while i<=n:
#print(“%.1f %.4f”, i, math.cos(i))
print(“%.1f %.4f” % (i,math.cos(i)))
i = i + 0.1
    =================================
See Output

Still stressed from student homework?
Get quality assistance from academic writers!