From 3f21bf326a3c55c67742c5790acdb765a5173a4e Mon Sep 17 00:00:00 2001
From: Hong-Phuc Bui <hong-phuc.bui@htwsaar.de>
Date: Sun, 21 Apr 2024 00:48:46 +0200
Subject: [PATCH] beispielen

---
 python-grundlage/arithmetische-operationen-cli.py           |   33 ++++++++
 python-grundlage/check-leapyear.py                          |    8 ++
 python-grundlage/easter-calculator.py                       |   24 ++++++
 python-grundlage/print-htw.py                               |   11 ++
 python-grundlage/quadratic-equation.py                      |   17 ++++
 python-grundlage/arithmetische-operationen.py               |   32 ++++++++
 python-grundlage/c/size_of_test.c                           |   15 +++
 python-grundlage/weekdays.py                                |    3 
 python-grundlage/color-spectral.py                          |   31 +++++++
 python-grundlage/package-example/experiments/physik.py      |    5 +
 python-grundlage/package-example/experiments/__init__.py    |    0 
 python-grundlage/package-example/__init__.py                |    0 
 python-grundlage/package-example/experiments/physik_test.py |   15 +++
 python-grundlage/package-example/use_experiment.py          |    7 +
 14 files changed, 201 insertions(+), 0 deletions(-)

diff --git a/python-grundlage/arithmetische-operationen-cli.py b/python-grundlage/arithmetische-operationen-cli.py
new file mode 100644
index 0000000..83bb621
--- /dev/null
+++ b/python-grundlage/arithmetische-operationen-cli.py
@@ -0,0 +1,33 @@
+#! /usr/bin/env python
+# -*-encoding utf-8-*-
+
+import sys
+
+a = sys.argv[1]
+b = sys.argv[2]
+
+a = float(a)
+b = float(b)
+
+plus = a + b
+print(f"{a} + {b} = {plus}")
+
+minus = a - b
+print(f"{a} - {b} = {minus}")
+
+mul = a * b
+print(f"{a} * {b} = {mul}")
+
+div = a / b
+print(f"{a} / {b} = {div}")
+
+integer_div = a // b
+print(f"{a} // {b} = {integer_div}")
+
+mod = a % b
+print(f"{a} % {b} = {mod}")
+
+exp = a ** b
+print(f"{a} ** {b} = {exp}")
+
+
diff --git a/python-grundlage/arithmetische-operationen.py b/python-grundlage/arithmetische-operationen.py
new file mode 100644
index 0000000..a25f80f
--- /dev/null
+++ b/python-grundlage/arithmetische-operationen.py
@@ -0,0 +1,32 @@
+#! /usr/bin/env python
+# -*-encoding utf-8-*-
+
+a = input("Geben Sie eine Zahl ein! ")
+b = input("Geben Sie eine weiter Zahl ein! ")
+
+
+a = float(a)
+b = float(b)
+
+plus = a + b
+print(f"{a} + {b} = {plus}")
+
+minus = a - b
+print(f"{a} - {b} = {minus}")
+
+mul = a * b
+print(f"{a} * {b} = {mul}")
+
+div = a / b
+print(f"{a} / {b} = {div}")
+
+integer_div = a // b
+print(f"{a} // {b} = {integer_div}")
+
+mod = a % b
+print(f"{a} % {b} = {mod}")
+
+exp = a ** b
+print(f"{a} ** {b} = {exp}")
+
+
diff --git a/python-grundlage/c/size_of_test.c b/python-grundlage/c/size_of_test.c
new file mode 100644
index 0000000..126d595
--- /dev/null
+++ b/python-grundlage/c/size_of_test.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <stdbool.h>
+
+int main() {
+    const unsigned int max = 4294967295;
+    const unsigned int max_as_negativ = -1;
+    printf("%d\n", max); // expected output: -1
+    printf("%u\n", max);
+    bool same = max == max_as_negativ;
+    if(same)
+    {
+        printf("%d and %u are the same in type unsigned int\n", max, max_as_negativ);
+    }
+    return 0;
+}
diff --git a/python-grundlage/check-leapyear.py b/python-grundlage/check-leapyear.py
new file mode 100644
index 0000000..8cd8990
--- /dev/null
+++ b/python-grundlage/check-leapyear.py
@@ -0,0 +1,8 @@
+#! /usr/bin/env python
+
+year = input("Geben Sie das Jahr ein! ")
+year = int(year)
+is_leap_year = ((year % 4 == 0) and (year % 100 != 0)) or (year % 400 == 0)
+
+print(is_leap_year)
+
diff --git a/python-grundlage/color-spectral.py b/python-grundlage/color-spectral.py
new file mode 100644
index 0000000..f6259a2
--- /dev/null
+++ b/python-grundlage/color-spectral.py
@@ -0,0 +1,31 @@
+#! /usr/bin/env
+
+
+violet = 380
+blau = 430
+cyan = 485
+gruen = 495
+gelb = 565
+orange = 590
+rot = 625
+infrarot = 780
+
+wellenlaenge = float(input("Geben Sie die Wellenlänge in nm ein "))
+
+if violet <= wellenlaenge <= infrarot:
+    if wellenlaenge < blau:
+        print("Violet")
+    elif wellenlaenge < cyan:
+        print("Blau")
+    elif wellenlaenge < gruen:
+        print("Cyan")
+    elif wellenlaenge < gelb:
+        print("Grün")
+    elif wellenlaenge < orange:
+        print("Gelb")
+    elif wellenlaenge < rot:
+        print("Orange")
+    elif wellenlaenge < infrarot:
+        print("Rot")
+else:
+    print("Nicht in sichtbarer Bereich")
diff --git a/python-grundlage/easter-calculator.py b/python-grundlage/easter-calculator.py
new file mode 100644
index 0000000..f05eecf
--- /dev/null
+++ b/python-grundlage/easter-calculator.py
@@ -0,0 +1,24 @@
+#! /usr/bin/env python
+# -*-encoding utf-8-*-
+
+
+year_input = input("Geben Sie das Jahr ein! (4-Ziffer) ")
+
+year = int(year_input)
+k = year // 100
+m = 15 + ((3*k + 3)//4) - ((8*k + 13)//25)
+s = 2 - (3*k + 3) // 4
+a = year % 19
+d = (19*a + m) % 30
+r = (d + a//11) // 29
+og = 21 + d - r
+sz = 7 - (year + (year//4) + s) % 7
+oe = 7 - ((og - sz) % 7)
+os = og + oe
+
+if os <= 31:
+    print(f"Der Ostersonntag ist {os}.ter März")
+else:
+    os = os % 31
+    print(f"Der Ostersonntag is {os}.ter April")
+
diff --git a/python-grundlage/package-example/__init__.py b/python-grundlage/package-example/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/python-grundlage/package-example/__init__.py
diff --git a/python-grundlage/package-example/experiments/__init__.py b/python-grundlage/package-example/experiments/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/python-grundlage/package-example/experiments/__init__.py
diff --git a/python-grundlage/package-example/experiments/physik.py b/python-grundlage/package-example/experiments/physik.py
new file mode 100644
index 0000000..2dad2b5
--- /dev/null
+++ b/python-grundlage/package-example/experiments/physik.py
@@ -0,0 +1,5 @@
+from typing import Any
+
+
+def do_something(arg: Any):
+    return arg
diff --git a/python-grundlage/package-example/experiments/physik_test.py b/python-grundlage/package-example/experiments/physik_test.py
new file mode 100644
index 0000000..55482d0
--- /dev/null
+++ b/python-grundlage/package-example/experiments/physik_test.py
@@ -0,0 +1,15 @@
+import unittest
+from physik import do_something
+
+
+class MyTestCase(unittest.TestCase):
+    def test_something(self):
+        arg = 123456
+        result = do_something(arg)
+        self.assertEqual(arg, result)
+
+
+if __name__ == '__main__':
+    unittest.main()
+
+
diff --git a/python-grundlage/package-example/use_experiment.py b/python-grundlage/package-example/use_experiment.py
new file mode 100644
index 0000000..cdc91f5
--- /dev/null
+++ b/python-grundlage/package-example/use_experiment.py
@@ -0,0 +1,7 @@
+from experiments import physik
+
+
+arg = 123456
+result = physik.do_something(arg)
+print(result)
+
diff --git a/python-grundlage/print-htw.py b/python-grundlage/print-htw.py
new file mode 100644
index 0000000..a8cce89
--- /dev/null
+++ b/python-grundlage/print-htw.py
@@ -0,0 +1,11 @@
+htw = '''
+HH         HH    TTTTTTTTTTTT    WW                    WW
+HH         HH         TT          WW                  WW
+HH         HH         TT           WW                WW
+HHhhhhhhhhhHH         TT            WW     WWWW     WW
+HH         HH         TT             WW   WW  WW   WW
+HH         HH         TT              WW WW    WW WW
+HH         HH         TT               WW       WW
+'''
+
+print(htw)
diff --git a/python-grundlage/quadratic-equation.py b/python-grundlage/quadratic-equation.py
new file mode 100644
index 0000000..1a45e11
--- /dev/null
+++ b/python-grundlage/quadratic-equation.py
@@ -0,0 +1,17 @@
+#! /usr/bin/env python
+# -*-  coding: utf-8 -*-
+
+import cmath
+
+print("Programm zur Lösung einer quadratischer Gleichung ax^2 + bx + c = 0")
+a = float(input("a = "))
+b = float(input("b = "))
+c = float(input("c = "))
+
+determinant = b**2 - 4*a*c
+d = cmath.sqrt(determinant)
+x1 = (-b - d) / (2*a)
+x2 = (-b + d) / (2*a)
+print(f"Gleichung: {a}x^2 + {b}x + {c} = 0")
+print(f"x1 = {x1}")
+print(f"x2 = {x2}")
\ No newline at end of file
diff --git a/python-grundlage/weekdays.py b/python-grundlage/weekdays.py
new file mode 100644
index 0000000..ed9543c
--- /dev/null
+++ b/python-grundlage/weekdays.py
@@ -0,0 +1,3 @@
+for t in range(0,7):
+    s = (7 - t) % 7 + 1
+    print(f"{t} → {s}")

--
Gitblit v1.10.0-SNAPSHOT