From e81f83c294a3f93153996dc3f9ab67c33ac7d431 Mon Sep 17 00:00:00 2001 From: Mika Date: Thu, 2 Nov 2023 13:56:12 +0100 Subject: [PATCH] =?UTF-8?q?Error=20handling=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mustergenerator.py | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/mustergenerator.py b/mustergenerator.py index a905875..2631b80 100644 --- a/mustergenerator.py +++ b/mustergenerator.py @@ -5,7 +5,6 @@ import math class Circle: def __init__(self, name: str, filepath: str, length=1000, height=1000, radius=10, distance=60, offset=50): - # run validations assert length >= 0, "length can not be negative" assert height >= 0, "height can not be negative" assert radius >= 0, "radius can not be negative" @@ -13,7 +12,6 @@ class Circle: assert offset >= 0, "offset can only be 0 - 100 %" assert offset <= 100, "offset can only be 0 - 100 %" - # Assign to self object self.__length = length self.__height = height self.__radius = radius @@ -108,26 +106,31 @@ if __name__ == '__main__': print(f"\nStandardwerte\nHöhe: {circle.height} px\nLänge: {circle.length} px\nRadius: {circle.radius} px\nAbstand: {circle.distance} px\nOffset: {circle.offset_percentage} %\n") selection_flag = True while selection_flag: - parameter_selection = int(input("Parameter ändern (0: keinen Parameter ändern, 1: Höhe, 2: Länge, 3: Radius, 4: Abstand, 5: Offste):")) - if parameter_selection == 0: - selection_flag = False - elif parameter_selection == 1: - height = int(input("Höhe in Pixeln eingeben:")) - circle.height = height - elif parameter_selection == 2: - length = int(input("Länge in Pixeln:")) - circle.length = length - elif parameter_selection == 3: - radius = int(input("Radius in Pixeln:")) - circle.radius = radius - elif parameter_selection == 4: - distance = int(input("Abstand in Pixeln:")) - circle.distance = distance - elif parameter_selection == 5: - offset = int(input("Offset in %:")) - circle.offset = offset - else: + try: + parameter_selection = int(input("Parameter ändern (0: keinen Parameter ändern, 1: Höhe, 2: Länge, 3: Radius, 4: Abstand, 5: Offste):")) + if parameter_selection == 0: + selection_flag = False + elif parameter_selection == 1: + height = int(input("Höhe in Pixeln eingeben:")) + circle.height = height + elif parameter_selection == 2: + length = int(input("Länge in Pixeln:")) + circle.length = length + elif parameter_selection == 3: + radius = int(input("Radius in Pixeln:")) + circle.radius = radius + elif parameter_selection == 4: + distance = int(input("Abstand in Pixeln:")) + circle.distance = distance + elif parameter_selection == 5: + offset = int(input("Offset in %:")) + circle.offset = offset + else: + print("ungültiger Wert") + except ValueError: print("ungültiger Wert") + except AssertionError as error: + print(error) circle.circle_generation() elif shape == 2: