Python Forum
Number bug, calculation is wrong
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Number bug, calculation is wrong
#1
so here is my code
        elif im.lower() in ("inh, inhalation, inhala"):     # inhalation
            barn = (input("Barn eller voksen? "))
            if barn.lower() in ("voksen", "vok"):           # to adults
                print("1 mg blandes op i 2 ml saltvand og gives på nebulisator")
            elif barn.lower() in ("barn", "ba", "bar"):     # to child
                vaegt = int(input("Hvad vejer barnet? "))
                inhalation = vaegt * 0.1  #Here is what should be calculated
                if inhalation > 1:
                    print("1 mg blandes op i 2 ml saltvand og gives på nebulisator")
                else:
                    print(inhalation, "mg blandes op i 2 ml saltvand og gives på nebulisator") #This is broken, i think.
if you type in "7" in line 6, the output will be 0.7000000000000001. it just needs to be 0.7. why does it do that?
i am writing in JetBrains pycharm
Reply


Messages In This Thread
Number bug, calculation is wrong - by d3fi - Aug-26-2019, 09:11 PM
RE: Number bug, calculation is wrong - by perfringo - Aug-27-2019, 05:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,387 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,602 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  python gives wrong string length and wrong character thienson30 2 2,943 Oct-15-2019, 08:54 PM
Last Post: Gribouillis
  Correct number wrong position func. albry 5 5,961 Jan-11-2019, 04:01 PM
Last Post: Larz60+
  [Regex] Findall returns wrong number of hits Winfried 8 5,686 Aug-23-2018, 02:21 PM
Last Post: Winfried

Forum Jump:

User Panel Messages

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