Related questions with answers
Question
Write a program that reads in two floating-point numbers and tests whether they are the same up to two decimal places. Here are two sample runs. Enter a floating-point number: 2.0 Enter a floating-point number: 1.99998 They are the same up to two decimal places. Enter a floating-point number: 2.0 Enter a floating-point number: 1.98999 They are different.
Solution
VerifiedAnswered 7 months ago
Answered 7 months ago
Step 1
1 of 2# convert inputs to float
num1 = float(input("Enter a first floating-point number: "))
num2 = float(input("Enter a second floating-point number: "))
# round(num1, 2) returns
# num1 round to two decimal places
num1 = round(num1, 2)
num2 = round(num2, 2)
# if they are equal after the rounding
# they are the same up to 2 decimal places
if num1 == num2:
print("They are the same up to two decimal places.")
# otherwise, they are different
else:
print("They are different.")
Create an account to view solutions
By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Create an account to view solutions
By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Recommended textbook solutions

Computer Organization and Design MIPS Edition: The Hardware/Software Interface
5th Edition•ISBN: 9780124077263 (4 more)David A. Patterson, John L. Hennessy220 solutions

Fundamentals of Database Systems
7th Edition•ISBN: 9780133970777 (3 more)Ramez Elmasri, Shamkant B. Navathe687 solutions

Introduction to Algorithms
3rd Edition•ISBN: 9780262033848 (3 more)Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen726 solutions

Python for Everyone
2nd Edition•ISBN: 9781119056553 (1 more)Cay S. Horstmann, Rance D. Necaise730 solutions
More related questions
1/4
1/7