-2
import math

x = float(input('Enter value of x \n'))

print ('\n')

if x < 5: 
    
   print ('The value of f(x) is \n')
    
   print (((x**2)/(abs(x)+2))**2)

How to set up the code so that when the line "print (((x**2)/(abs(x)+2))**2)" runs it also rounds the output value?

Sophia
  • 1
  • 1
  • 1
    Badly indented Python code is _invalid_ python code. Please [edit] your question to ensure the code is indented correctly. – Pranav Hosangadi Feb 08 '21 at 17:22
  • 1
    Please also take the [tour], and read [what's on-topic here](/help/on-topic), [ask], and the [question checklist](//meta.stackoverflow.com/q/260648/843953). [Asking on Stack Overflow is not a substitute for doing your own research.](//meta.stackoverflow.com/a/261593/843953) – Pranav Hosangadi Feb 08 '21 at 17:23
  • 1
    Does this answer your question? [Safest way to convert float to integer in python?](https://stackoverflow.com/questions/3387655/safest-way-to-convert-float-to-integer-in-python) – Pranav Hosangadi Feb 08 '21 at 17:24
  • Round to the nearest integer. – Sophia Feb 08 '21 at 17:28

1 Answers1

0

import math

x = float(input('Enter value of x \n'))

print ('\n')

if x < 5:

    y1 = round(((x**2)/(abs(x)+2))**2)

    print ('The value of f(x) is \n')

    print(y1)
Sophia
  • 1
  • 1