this is in python 3.6
Write a program that prints to three significant figures the values of x and g(x) from x = 0 to x = 10 in increments of 2 units.
The values of x include 0 and 10.
The function g(x) is defined below:
g(x): sqrt(x); x<4
sqrt(4); 4<=x
The output of the first and last values are below:
0.000 0.000
... ...
10.000 2.000
code:
import math
# funtion g(x) returns sqrt(x) when x<4 and returns
4<=x
def g(x):
if x<4:
# return sqrt(x)
return math.sqrt(x)
else:
# return sqrt(4)
return math.sqrt(4)
# for x = 0 to x = 10
for x in range(11):
print("{0:.4f} {1:.4f}".format(x,g(x)))
screenshot:
output:
//follow the screenshot of code for the indentation of the program
//if you like the answer please give an upvote and for any queries ask in comment
Get Answers For Free
Most questions answered within 1 hours.