Python Forum
ZeroDivisionError: float division by zero
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ZeroDivisionError: float division by zero
#8
You should split the GUI from code for calculation. Then you can test it better.
First comes the calculation:

Example:
class RoomSound:
    def __init__(self, length, width, height, area_window):
        self.length = length
        self.width = width
        self.height = height
        self.area_window = area_window

    @property
    def area(self):
        """
        Area in m²
        """
        return self.length * self.width

    @property
    def volume(self):
        """
        Volume in m³
        """
        return self.length * self.width * self.height

    @property
    def area_volume_ratio(self):
        return self.area / self.volume

    @property
    def area_room(self):
        """
        Area of room in m²
        """
        return 2 * self.length * self.height + 2 * self.height * self.width - self.area_window

    @property
    def reverberation(self):
        """
        Reverberation with sabine equation 
        """
        return 0.163 * self.area_volume_ratio


if __name__ == "__main__":
    length = 9.92  # Länge
    width = 10.5  # Breite
    height = 2.34  # Höhe
    A_f = 30.45  # Fensterfläche
    room1 = RoomSound(length, width, height, A_f)
    print(room1.area, room1.volume, room1.reverberation)
The parameters could expressed in dicts for example:
Instead of using indicies, you could use for example the name: "Stuhl"

objekte = {
    "Stuhl": 3.4533333333333336,
    "MP": 0.5916666666666667,
    "WP": 0.2833333333333334,
}

print(objekte["Stuhl"])
Or with the different sounds:
sounds = {
    "Musik": {"factor": 0.45, "offset": 0.07},
    "Sprache": {"factor": 0.37, "offset": -0.14},
    "Vortrag": {"factor": 0.32, "offset": -0.17},
    "Spr.+Vor.": {"factor": 0.26, "offset": -0.17},
    "Sport": {"factor": 0.75, "offset": -1},
}


def get_level(sound_type, V):
    sound = sounds[sound_type]
    return sound["factor"] * math.log10(V) + sound["offset"]


print(get_level("Musik", 20))
To get for example all type of sounds, use the keys:

print("Sounds:", list(sounds.keys()))
This would make the creation of the Listbox more dynamic.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: ZeroDivisionError: float division by zero - by DeaD_EyE - Feb-19-2020, 04:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] rez = (mass / h) | ZeroDivisionError Maryan 5 2,682 Oct-20-2020, 09:38 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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