Program-7
7) 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.
Note: 'abs' is a built-in math function in python which is used for absolute value.
from decimal import *
num1 = Decimal(input("Enter number 1 : "))
num2 = Decimal(input("Enter number 2 : "))
diff=abs(num1-num2)
if (diff<=0.001):
print("close")
else:
print("Not Close")
OUTPUT:
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
====== RESTART: D:/old/r19 lab-python/7.py =========
Enter number 1 : 12.003
Enter number 2 : 12.004
close
No comments:
Post a Comment