CBSE Class 11 Computer Science Question 127 of 161

Flow of Control — Question 4

Back to all questions
4
Question

Question 4

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.

Solution
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))

d = 0
if a > b :
    d = a - b
else : 
    d = b - a

if d <= 0.001 :
    print("Close")
else :
    print("Not Close")
Output
Enter first number: 10.12345
Enter second number: 10.12354
Close
Answer