From bf0dd3f17baf1b4c655b823f9b9c1f0b0364a503 Mon Sep 17 00:00:00 2001 From: Hong-Phuc Bui <hong-phuc.bui@htwsaar.de> Date: Tue, 22 Apr 2025 16:33:14 +0200 Subject: [PATCH] 2. Vorlesung --- 02-eingabe-ausgabe/Inhalt.md | 30 +++++++++++++++ 02-eingabe-ausgabe/gauss-ostern.py | 32 ++++++++++++++++ 2 files changed, 62 insertions(+), 0 deletions(-) diff --git a/02-eingabe-ausgabe/Inhalt.md b/02-eingabe-ausgabe/Inhalt.md new file mode 100644 index 0000000..120cbae --- /dev/null +++ b/02-eingabe-ausgabe/Inhalt.md @@ -0,0 +1,30 @@ +# Entscheidung treffen + +```python +if os <= 31: + tag = os + monat = "März" +else: + tag = os-31 + monat = "April" +``` + +# Wiederholung + +## Die `while`-Schleife + +```python +while not eingabe_ok: + # ... +``` + +# Ausnahmesituation mit `try`-`except + +```python +try: + jahr_input = input("Geben Sie die Jahresnummer ein") + x = int(jahr_input) + eingabe_ok = True +except: + print("Eingabe ist keine Zahl") +``` diff --git a/02-eingabe-ausgabe/gauss-ostern.py b/02-eingabe-ausgabe/gauss-ostern.py new file mode 100644 index 0000000..40adffa --- /dev/null +++ b/02-eingabe-ausgabe/gauss-ostern.py @@ -0,0 +1,32 @@ + +eingabe_ok = False + +while not eingabe_ok: + try: + jahr_input = input("Geben Sie die Jahresnummer ein") + x = int(jahr_input) + eingabe_ok = True + except: + print("Eingabe ist keine Zahl") + +a = x % 19 +k = x // 100 +m = 15 + (3*k + 3) // 4 - (8*k + 13) // 25 +d = (19*a + m) % 30 +s = 2 - (3*k + 3) // 4 +r = (d + a // 11) // 29 +og = 21 + d - r +sz = 7 - (x + x//4 + s) % 7 +oe = 7 - (og - sz) % 7 +os = (og + oe) + +if os <= 31: + tag = os + monat = "März" +else: + tag = os-31 + monat = "April" + +print(f"Der Ostersonntag im {x} ist am {tag}ten {monat}") + + -- Gitblit v1.10.0-SNAPSHOT