From 7f5f315ce79b213b153684910c20654039a91369 Mon Sep 17 00:00:00 2001
From: Hong-Phuc Bui <hong-phuc.bui@htwsaar.de>
Date: Wed, 15 May 2024 14:48:57 +0200
Subject: [PATCH] Template 4 Students OK

---
 funktion-modular/study-effort/effort_semester.py |   31 +++++++++++++++++++------------
 1 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/funktion-modular/study-effort/effort_semester.py b/funktion-modular/study-effort/effort_semester.py
index 2238ffc..24bca67 100644
--- a/funktion-modular/study-effort/effort_semester.py
+++ b/funktion-modular/study-effort/effort_semester.py
@@ -24,7 +24,7 @@
                                                        <>
 """
 import sys
-from typing import Final
+from typing import Final, Any
 
 SEMESTER_LENGTH: Final[int] = 15  # 15 Woche pro Semester
 ECTS_EFFORT = 30  # 1 ECTS ~ 30 h
@@ -63,24 +63,31 @@
 
 
 def print_effort(effort: list[tuple[str, float, float, float]]) -> None:
-    max_char = 0
+    header = ("Vorlesung", "ECTS", "V;U;T/Woche", "Aufwand/Woche")
+    max_char = len(header)
     sep_width = 3
     sum_effort = 0
     for l in effort:
-        if l := len(l[0]) > max_char:
-            max_char = l
+        if (c := len(l[0])) > max_char:
+            max_char = c
         sum_effort += l[-1]
 
     lecture_col_width = sep_width + max_char
-    ects_width = len("ECTS") + 1
-    veranstaltung_col_width = 5
-    header = ("Vorlesung", "ECTS", "V;U;T/Woche", "Aufwand/Woche")
+    ects_width = len(header[1])
+    veranstaltung_col_width = len(header[2])
+    effort_col_width = len(header[3])
+
+    def format_line(line: list[tuple[Any, Any, Any, Any]] ):
+        lecture = f"{line[0]}".rjust(lecture_col_width)
+        ects = f"{line[1]}".center(ects_width)
+        v = f"{line[2]}".center(veranstaltung_col_width)
+        e = f"{line[3]}".center(effort_col_width)
+        return f"{lecture}  {ects}  {v}  {e}"
+
+    print(format_line(header))
     for l in effort:
-        lecture = l[0].rjust(lecture_col_width)
-        ects = f"{l[1]}".ljust(ects_width)
-        v = f"{l[2]}".rjust(veranstaltung_col_width)
-        e = f"{l[3]}".rjust(veranstaltung_col_width)
-        print(f"{lecture} {ects} {v} {e}")
+        print(format_line(l))
+
     print(f"Summe: {sum_effort}")
 
 

--
Gitblit v1.10.0-SNAPSHOT