Abgabe Überarbeitet
parent
af70a5f8ac
commit
6f6b7ef702
BIN
s1_a1_3_52.pdf
BIN
s1_a1_3_52.pdf
Binary file not shown.
24
s1_a4.py
24
s1_a4.py
|
@ -1,9 +1,15 @@
|
||||||
i = 0
|
#4.1
|
||||||
s = 0.0
|
import math
|
||||||
while s <= 1.644934:
|
|
||||||
i = i + 1
|
z = ((math.pi**2)/6)
|
||||||
s = s + 1.0 / (i * i)
|
x = "%(z).6f"%{'z':(math.pi**2)/6}
|
||||||
print("Schritt: " + str(i) + ", Wert: " + str(s))
|
y = 1.644934
|
||||||
|
print(x)
|
||||||
|
|
||||||
#pi^2/6 = 1,644934, wird erreicht nach 14959887 Schritten
|
|
||||||
|
i = 1
|
||||||
|
sum = 0
|
||||||
|
while sum < y:
|
||||||
|
sum = sum + (1 / (i ** 2))
|
||||||
|
i = i + 1
|
||||||
|
print("Summe:", sum, ", Schritte: ", i) #Summe: 1.6449340000000012, Schritte: 14959887
|
||||||
|
|
39
s1_a51.py
39
s1_a51.py
|
@ -1,19 +1,20 @@
|
||||||
# 1a
|
#5.1
|
||||||
matrix_list = [[3, 0, -2, 11], [0, 0, 9, 0], [0, 7, 0, 0], [0, 0, 0, -3]]
|
#a)
|
||||||
print(matrix_list)
|
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 = [[], [], [], []]
|
#b+c)
|
||||||
MAX = 4
|
matrix_list_general = [[], [], [], []]
|
||||||
for i in range(0, MAX):
|
MAX = 4
|
||||||
print("Zeile " + str(i + 1))
|
for i in range(0, MAX):
|
||||||
for j in range(0, MAX):
|
print("Zeile " + str(i + 1))
|
||||||
n = int(input("Value:"))
|
for j in range(0, MAX):
|
||||||
matrix_list_general[i].insert(j, n)
|
n = int(input("Value:"))
|
||||||
|
matrix_list_general[i].insert(j, n)
|
||||||
print(matrix_list_general)
|
|
||||||
|
print(matrix_list_general)
|
||||||
# 1d
|
|
||||||
for i, row in enumerate(matrix_list_general):
|
#d)
|
||||||
for j, value in enumerate(row):
|
for i, row in enumerate(matrix_list_general):
|
||||||
print(f'a[{i}][{j}] = {value} ')
|
for j, value in enumerate(row):
|
||||||
|
print(f'a[{i}][{j}] = {value} ')
|
||||||
|
|
95
s1_a53_6.py
95
s1_a53_6.py
|
@ -1,43 +1,52 @@
|
||||||
#5_3
|
#5.3
|
||||||
list1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
list1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||||
print("start list", list1)
|
print("start list: ", list1)
|
||||||
|
|
||||||
a = list1[9]
|
list1.insert(0, list1.pop())
|
||||||
b = list1[8]
|
list1.insert(0, list1.pop())
|
||||||
c = list1[7]
|
list1.insert(0, list1.pop())
|
||||||
|
|
||||||
list1 = [c] + [b] + [a] + list1
|
print("new list: ", list1)
|
||||||
list1.pop(-1)
|
print()
|
||||||
list1.pop(-1)
|
print()
|
||||||
list1.pop(-1)
|
|
||||||
|
#---------------------------------------------------------------------------------------------------------
|
||||||
print("new list", list1)
|
|
||||||
print()
|
#5.4
|
||||||
print()
|
#a
|
||||||
|
word = "DONAUDAMPFSCHIFFAHRTSGESELLSCHAFTSSTEWARDESS"
|
||||||
#5_4
|
letters = list(word)
|
||||||
#a
|
print(letters)
|
||||||
word = "DONAUDAMPFSCHIFFAHRTSGESELLSCHAFTSSTEWARDESS"
|
print("length:", len(letters))
|
||||||
letters = list(word)
|
|
||||||
print(letters)
|
#b
|
||||||
print("length:", len(letters))
|
letters_once = []
|
||||||
|
for element in letters:
|
||||||
#b
|
if element not in letters_once:
|
||||||
letters_once = []
|
letters_once.append(element)
|
||||||
for element in letters:
|
|
||||||
if element not in letters_once:
|
print(letters_once)
|
||||||
letters_once.append(element)
|
print("new length:", len(letters_once))
|
||||||
|
|
||||||
print(letters_once)
|
print()
|
||||||
print("length new:", len(letters_once))
|
print()
|
||||||
|
|
||||||
print()
|
#---------------------------------------------------------------------------------------------------------
|
||||||
print()
|
|
||||||
|
#5.5
|
||||||
#5_5
|
list2 = [[1, 2, 3], [2, 1, 3], [4, 0, 1]]
|
||||||
def sort(list2):
|
print("List2 unsorted:", list2)
|
||||||
list2.sort(key = lambda x: x[1])
|
list2.sort(key = lambda list2: list2[1])
|
||||||
return list2
|
print("List2 sorted by 2nd value:", list2)
|
||||||
|
print()
|
||||||
list2 = [[1, 2, 3], [2, 1, 3], [4, 0, 1]]
|
print()
|
||||||
print(sort(list2))
|
#---------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#5.6
|
||||||
|
dict = { "Hund" : "wuff", "Katze" : "miau", "Kuh" : "muuh" }
|
||||||
|
def function2(d, a):
|
||||||
|
print(a, ":", d[a])
|
||||||
|
|
||||||
|
function2(dict, "Hund")
|
||||||
|
function2(dict, "Katze")
|
||||||
|
function2(dict, "Kuh")
|
||||||
|
|
16
s1_a61_2.py
16
s1_a61_2.py
|
@ -1,6 +1,10 @@
|
||||||
string = "this is a test"
|
#6.
|
||||||
replaced = string.replace(' ', '-')
|
s = "This is a test"
|
||||||
print(replaced)
|
print(s)
|
||||||
|
|
||||||
string2 = "hello, world"[-7::-1]
|
#1.
|
||||||
print(string2)
|
print("Spaces replaced with '-':", s.replace(' ', '-'))
|
||||||
|
|
||||||
|
#2.
|
||||||
|
s1 = "Hello, World"[-7::-1]
|
||||||
|
print(s1)
|
||||||
|
|
Loading…
Reference in New Issue