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: class Circle:
def __init__(self, name: str, filepath: str, length=1000, height=1000, radius=10, distance=60, offset=50): 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 length >= 0, "length can not be negative"
assert height >= 0, "height can not be negative" assert height >= 0, "height can not be negative"
assert radius >= 0, "radius 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 >= 0, "offset can only be 0 - 100 %"
assert offset <= 100, "offset can only be 0 - 100 %" assert offset <= 100, "offset can only be 0 - 100 %"
# Assign to self object
self.__length = length self.__length = length
self.__height = height self.__height = height
self.__radius = radius self.__radius = radius
@ -108,6 +106,7 @@ 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") 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 selection_flag = True
while selection_flag: while selection_flag:
try:
parameter_selection = int(input("Parameter ändern (0: keinen Parameter ändern, 1: Höhe, 2: Länge, 3: Radius, 4: Abstand, 5: Offste):")) 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: if parameter_selection == 0:
selection_flag = False selection_flag = False
@ -128,6 +127,10 @@ if __name__ == '__main__':
circle.offset = offset circle.offset = offset
else: else:
print("ungültiger Wert") print("ungültiger Wert")
except ValueError:
print("ungültiger Wert")
except AssertionError as error:
print(error)
circle.circle_generation() circle.circle_generation()
elif shape == 2: elif shape == 2: