Error handling hinzugefügt

This commit is contained in:
Mika 2023-11-02 13:56:12 +01:00
parent 5b2b84dbf0
commit e81f83c294

View File

@ -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: