From ed7af558eac238b6fe2d379efba7f6cc2078743f Mon Sep 17 00:00:00 2001 From: Blues44 Date: Tue, 15 Nov 2022 14:51:35 +0100 Subject: [PATCH] Abgabe .py Teile --- s1_a4.py | 9 +++++++++ s1_a51.py | 19 +++++++++++++++++++ s1_a53_6.py | 43 +++++++++++++++++++++++++++++++++++++++++++ s1_a61_2.py | 6 ++++++ 4 files changed, 77 insertions(+) create mode 100644 s1_a4.py create mode 100644 s1_a51.py create mode 100644 s1_a53_6.py create mode 100644 s1_a61_2.py diff --git a/s1_a4.py b/s1_a4.py new file mode 100644 index 0000000..246adbc --- /dev/null +++ b/s1_a4.py @@ -0,0 +1,9 @@ +i = 0 +s = 0.0 +while s <= 1.644934: + i = i + 1 + s = s + 1.0 / (i * i) + print("Schritt: " + str(i) + ", Wert: " + str(s)) + + +#pi^2/6 = 1,644934, wird erreicht nach 14959887 Schritten \ No newline at end of file diff --git a/s1_a51.py b/s1_a51.py new file mode 100644 index 0000000..bf77602 --- /dev/null +++ b/s1_a51.py @@ -0,0 +1,19 @@ +# 1a +matrix_list = [[3, 0, -2, 11], [0, 0, 9, 0], [0, 7, 0, 0], [0, 0, 0, -3]] +print(matrix_list) + +# 1b+c +matrix_list_general = [[], [], [], []] +MAX = 4 +for i in range(0, MAX): + print("Zeile " + str(i + 1)) + for j in range(0, MAX): + n = int(input("Value:")) + matrix_list_general[i].insert(j, n) + +print(matrix_list_general) + +# 1d +for i, row in enumerate(matrix_list_general): + for j, value in enumerate(row): + print(f'a[{i}][{j}] = {value} ') \ No newline at end of file diff --git a/s1_a53_6.py b/s1_a53_6.py new file mode 100644 index 0000000..3861705 --- /dev/null +++ b/s1_a53_6.py @@ -0,0 +1,43 @@ +#5_3 +list1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] +print("start list", list1) + +a = list1[9] +b = list1[8] +c = list1[7] + +list1 = [c] + [b] + [a] + list1 +list1.pop(-1) +list1.pop(-1) +list1.pop(-1) + +print("new list", list1) +print() +print() + +#5_4 +#a +word = "DONAUDAMPFSCHIFFAHRTSGESELLSCHAFTSSTEWARDESS" +letters = list(word) +print(letters) +print("length:", len(letters)) + +#b +letters_once = [] +for element in letters: + if element not in letters_once: + letters_once.append(element) + +print(letters_once) +print("length new:", len(letters_once)) + +print() +print() + +#5_5 +def sort(list2): + list2.sort(key = lambda x: x[1]) + return list2 + +list2 = [[1, 2, 3], [2, 1, 3], [4, 0, 1]] +print(sort(list2)) \ No newline at end of file diff --git a/s1_a61_2.py b/s1_a61_2.py new file mode 100644 index 0000000..51b5784 --- /dev/null +++ b/s1_a61_2.py @@ -0,0 +1,6 @@ +string = "this is a test" +replaced = string.replace(' ', '-') +print(replaced) + +string2 = "hello, world"[-7::-1] +print(string2) \ No newline at end of file