[Solved] Print function values [closed]


import numpy as np

x_range = np.arange(-3, -0.8, 0.2)
for x in x_range:
  y = (x**2)/2 - 4*x
  print("{:.2f} -> {:.2f}".format(x, y))

if you want to store the y values for each x:

import numpy as np

x_range = np.arange(-3, -0.8, 0.2)
y_vals = []
for x in x_range:
  y = (x**2)/2 - 4*x
  y_vals.append(y)

print(np.around(y_vals, decimals=2))

without numpy:

y_vals = []
for x in range(-30,-8,2):
  x /= 10.0 # can't have floats in range()
  y = (x**2)/2 - 4*x
  y_vals.append(y)

print(y_vals)

1

solved Print function values [closed]