PYTHON PROGRAM THAT ASKS USER FOR TWO NUMBERS AND PRINTS CLOSE IF NUMBERS ARE WITHIN .001 OF EACH OTHER AND NOT CLOSE OTHERWISE

 

Write a program that asks the user for two numbers and prints Close if the numbers are within .001 of each other and Not close otherwise.


CODE:

a=float(input("Enter a-value:"))

b=float(input("Enter b-value:"))

if abs(a-b)<=0.001:

    print("Close")

else:

    print("Not close")


EXPLANATION:

In this code, the program asks the user to enter two numbers a and b (a>b or b>a)

It finds their difference and returns an appropriate message if their difference is within 0.001(<=0.001).

Here we use abs() function to find their absolute difference.

Absolute value of a number is the value without considering its sign. Hence absolute of 10 is 10, -10 is also 10. If the number is a complex number, abs() returns its magnitude.

OUTPUT:



Comments

Popular posts from this blog

PYTHON PROGRAM THAT USES FOR LOOP TO PRINT THE NUMBERS 8,11,14,17,20,.........,83,86,89

PYTHON PROGRAM THAT ASKS THE USER TO ENTER TWO STRINGS OF SAME LENGTH AND WILL ALTERNATE THE CHARACTERS OF THE TWO STRINGS.FOR EXAMPLE: abcde and ABCDE THEN THE PROGRAM WILL PRINT AaBbCcDdEe

PYTHON PROGRAM THAT ASKS USER FOR LARGE INTEGERS AND INSERTS COMMAS INTO IT ACCORDING TO THE STANDARD AMERICAN CONVENTION FOR COMMAS IN LARGE NUMBERS