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 GENERATES A RANDOM NUMBER BETWEEN 1 AND 10 AND ASKS THE USER TO GUESS THE NUMBER

PYTHON PROGRAM THAT ASKS THE USER TO ENTER A WORD AND PRINTS OUT WHETHER THAT WORD CONTAINS ANY VOWELS