Python Forum
I'm trying to figure out if this is a bug from a simple quiz at Future Skill
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I'm trying to figure out if this is a bug from a simple quiz at Future Skill
#3
(Jan-25-2023, 03:21 PM)deanhystad Wrote: You can use numbers like 1e-9 instead of using the pow() function.
def equal(a, b, zero=1e-9):
    return abs(a-b) < zero

print(equal(1.1, 1.1))
print(equal(1.1, 1.1 + 1e-8))
print(equal(1.1, 1.1 + 1e-9))   # sketchy
print(equal(1.1, 1.1 + 1e-10))
Output:
True False False True
This works fairly well, but what if the numbers you are testing are near zero? If I compare 1e-9 and 1e-9+1e-10 the test will say they are equal even though they differ by 10%. I don't think using a fixed threshold is the correct way to solve this problem.

I'm trying to write my code from the function def level7_float_comparison(self, a, b):
But I'm baffled why I'm only getting 2 points and not 6/6 points.
Reply


Messages In This Thread
RE: I'm trying to figure out if this is a bug from a simple quiz at Future Skill - by fabstr1 - Jan-25-2023, 04:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I can't figure out simple rounding to 2 decimal places! Funnypants 7 3,437 Nov-01-2018, 01:38 AM
Last Post: j.crater
  Need To Create Simple Mutiple Choice Quiz In Tkinter Rashi 5 15,602 Apr-01-2017, 04:03 AM
Last Post: Rashi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020