diff --git a/Aufgabe03b.py b/Aufgabe03b.py new file mode 100644 index 0000000000000000000000000000000000000000..0421962ef9fe239b740c2a0c5b6088806d93a61e --- /dev/null +++ b/Aufgabe03b.py @@ -0,0 +1,22 @@ +from Aufgabe03a import Stack + +def end(c): + if c == "(": return ")" + if c == "[": return "]" + if c == "<": return ">" + if c == "{": return "}" + return None + +def check_klammern(s): + check_sum = Stack() + for c in s: + if c in ["(", "[", "<", "{"]: + check_sum.push(c) + elif c in [")", "]", ">", "}"]: + if check_sum.isEmpty(): + return False + elif c == end(check_sum.pop()): + continue + else: + return False + return check_sum.isEmpty()