Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)
I want to generate a code that should ask for one decimal number in Python and then computes the absolute value?

1 Answer

0 votes
by (108k points)

There are two ways of calculating the absolute value of a particular number. Either you use an in-built function named abs():

x=float(input('enter a float data: '))

absolute_val = abs(x)

Or you can simply calculate in the manual way(that is with maths):

x=float(input('enter a float data: '))

absolute_val = (x ** 2) ** 0.5

Want to become a Python Developer? Check out this insightful Python Certification course.

 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...