def function(x): return abs(x-1) + 0.5 for x in range(-5, 15): y = function(x) print(f"For x = {x}, y = {y}")
Результат:
For x = -5, y = 5.5 For x = -4, y = 4.5 For x = -3, y = 3.5 For x = -2, y = 2.5 For x = -1, y = 1.5 For x = 0, y = 0.5 For x = 1, y = 0.5 For x = 2, y = 1.5 For x = 3, y = 2.5 For x = 4, y = 3.5 For x = 5, y = 4.5 For x = 6, y = 5.5 For x = 7, y = 6.5 For x = 8, y = 7.5 For x = 9, y = 8.5 For x = 10, y = 9.5 For x = 11, y = 10.5 For x = 12, y = 11.5 For x = 13, y = 12.5 For x = 14, y = 13.5
return abs(x-1) + 0.5
for x in range(-5, 15):
y = function(x)
print(f"For x = {x}, y = {y}")
Результат:
For x = -5, y = 5.5For x = -4, y = 4.5
For x = -3, y = 3.5
For x = -2, y = 2.5
For x = -1, y = 1.5
For x = 0, y = 0.5
For x = 1, y = 0.5
For x = 2, y = 1.5
For x = 3, y = 2.5
For x = 4, y = 3.5
For x = 5, y = 4.5
For x = 6, y = 5.5
For x = 7, y = 6.5
For x = 8, y = 7.5
For x = 9, y = 8.5
For x = 10, y = 9.5
For x = 11, y = 10.5
For x = 12, y = 11.5
For x = 13, y = 12.5
For x = 14, y = 13.5