Skip to content
Snippets Groups Projects
Commit 069cfd6f authored by Christof Kaufmann's avatar Christof Kaufmann
Browse files

Notebooks from ckaufmann/akis-python-framework@a88e96b7

parent a9d1e1b5
No related branches found
No related tags found
No related merge requests found
Showing
with 879 additions and 0 deletions
%% Cell type:markdown id:0001-c4ebcae76a61e5c557bb02fd60a95e729bf4d6026594d5a5ee85cd38816 tags:
# Rechenoperatoren
Berechne verschiedene mathematische Operationen (`+`, `-`, `*`, `/`,
`//`, `%`, `**`) mit den untenstehenden Variablen als Operatoren. Gib
die Ergebnisse aus und bennene die Operationen.
%% Cell type:code id:0002-9200ab6778412655f2dfbd795d8f25fb12ab458c7b12fab2e75f141443e tags:
```
a = 10
b = 3
```
%% Cell type:markdown id:0011-188b432b6df51e25087558e034846c82f51c9751ecb9acfef89efdd07f7 tags:
## Lösung
``` python
summe = a + b # Addition
differenz = a - b # Subtraktion
produkt = a * b # Multiplikation
division = a / b # Division
ganzzahldivision = a // b # Ganzzahldivision
restwert = a % b # Rest der Division
potenz = a ** b # Potenz
```
``` python
print("Summe:", summe)
```
Summe: 13
``` python
print("Differenz:", differenz)
```
Differenz: 7
``` python
print("Produkt:", produkt)
```
Produkt: 30
``` python
print("Division:", division)
```
Division: 3.3333333333333335
``` python
print("Ganzzahldivision:", ganzzahldivision)
```
Ganzzahldivision: 3
``` python
print("Rest der Division:", restwert)
```
Rest der Division: 1
``` python
print("Potenz:", potenz)
```
Potenz: 1000
%% Cell type:markdown id:0001-c4ebcae76a61e5c557bb02fd60a95e729bf4d6026594d5a5ee85cd38816 tags:
# Rechenoperatoren
Berechne verschiedene mathematische Operationen (`+`, `-`, `*`, `/`,
`//`, `%`, `**`) mit den untenstehenden Variablen als Operatoren. Gib
die Ergebnisse aus und bennene die Operationen.
%% Cell type:code id:0002-9200ab6778412655f2dfbd795d8f25fb12ab458c7b12fab2e75f141443e tags:
```
a = 10
b = 3
```
%% Cell type:markdown id:0003-4f90926ab6960e65168fdff6f5e151194200dd69b468fb4eeb302fa84f1 tags:
Hier Ihr Code:
%% Cell type:code id:0004-44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 tags:
```
```
%% Cell type:markdown id:0001-9103dd25bb527fa8516853edbc26762e9518f44f626498a17522133f279 tags:
# Bitweise Operatoren
Führe bitweise Operationen (`&`, `|`, `^`, `~`, `<<`, `>>`) mit den
untenstehenden Variablen als Operanden aus. Gib die Ergebnisse aus und
bennene die Operationen.
%% Cell type:code id:0002-a42723601bad0fd7f2e25e3defb1950935ce6f286805266b2cfa14044a9 tags:
```
a = 5 # 101
b = 3 # 011
```
%% Cell type:markdown id:0010-99dfdacf7507c8384de8d991dfdb8e4a649721b7423d97867a830d5091a tags:
## Lösung
``` python
bitwise_and = a & b # Bitweise AND-Operation
bitwise_or = a | b # Bitweise OR-Operation
bitwise_xor = a ^ b # Bitweise XOR-Operation
bitwise_complement_a = ~a # Bitweise Komplement von a
bitwise_left_shift = a << b # Bitweise Linksverschiebung
bitwise_right_shift = a >> b # Bitweise Rechtsverschiebung
```
``` python
print("Bitweise AND:", bitwise_and)
```
Bitweise AND: 1
``` python
print("Bitweise OR:", bitwise_or)
```
Bitweise OR: 7
``` python
print("Bitweise XOR:", bitwise_xor)
```
Bitweise XOR: 6
``` python
print("Bitweise Komplement von a:", bitwise_complement_a)
```
Bitweise Komplement von a: -6
``` python
print("a um 3 Stellen nach links verschieben:", bitwise_left_shift) # also 5 * 2^3
```
a um 3 Stellen nach links verschieben: 40
``` python
print("a um 3 Stellen nach rechts verschieben:", bitwise_right_shift) # also 5 // 2^3
```
a um 3 Stellen nach rechts verschieben: 0
%% Cell type:markdown id:0001-9103dd25bb527fa8516853edbc26762e9518f44f626498a17522133f279 tags:
# Bitweise Operatoren
Führe bitweise Operationen (`&`, `|`, `^`, `~`, `<<`, `>>`) mit den
untenstehenden Variablen als Operanden aus. Gib die Ergebnisse aus und
bennene die Operationen.
%% Cell type:code id:0002-a42723601bad0fd7f2e25e3defb1950935ce6f286805266b2cfa14044a9 tags:
```
a = 5 # 101
b = 3 # 011
```
%% Cell type:markdown id:0003-4f90926ab6960e65168fdff6f5e151194200dd69b468fb4eeb302fa84f1 tags:
Hier Ihr Code:
%% Cell type:code id:0004-44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 tags:
```
```
%% Cell type:markdown id:0001-1e6ba89f1dc850c527ed89b25fd8c1fba9947490611d295296b506ff33a tags:
# Erweiterte Zuweisungsoperatoren
Führe erweiterte Zuweisungsoperationen (`+=` & co) mit der unten
gegebenen Zahl aus. Gib die Ergebnisse aus und bennene die Operationen.
%% Cell type:code id:0002-9cf911fd80de03363d8052564f07c57474aba81ca079715b60d005b0f8a tags:
```
zahl = 7
```
%% Cell type:markdown id:0007-521cfb536b2069c1e050d19cd803191c04e054ddf67f8b2ac8a59abf290 tags:
## Lösung
``` python
zahl += 3 # Erweiterte Addition: zahl = zahl + 3
print("Ergebnis nach += 3:", zahl)
```
Ergebnis nach += 3: 10
``` python
zahl -= 2 # Erweiterte Subtraktion: zahl = zahl - 2
print("Ergebnis nach -= 2:", zahl)
```
Ergebnis nach -= 2: 8
``` python
zahl *= 5 # Erweiterte Multiplikation: zahl = zahl * 5
print("Ergebnis nach *= 5:", zahl)
```
Ergebnis nach *= 5: 40
``` python
zahl /= 2 # Erweiterte Division: zahl = zahl / 2
print("Ergebnis nach /= 2:", zahl)
```
Ergebnis nach /= 2: 20.0
%% Cell type:markdown id:0001-1e6ba89f1dc850c527ed89b25fd8c1fba9947490611d295296b506ff33a tags:
# Erweiterte Zuweisungsoperatoren
Führe erweiterte Zuweisungsoperationen (`+=` & co) mit der unten
gegebenen Zahl aus. Gib die Ergebnisse aus und bennene die Operationen.
%% Cell type:code id:0002-9cf911fd80de03363d8052564f07c57474aba81ca079715b60d005b0f8a tags:
```
zahl = 7
```
%% Cell type:markdown id:0003-4f90926ab6960e65168fdff6f5e151194200dd69b468fb4eeb302fa84f1 tags:
Hier Ihr Code:
%% Cell type:code id:0004-44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 tags:
```
```
%% Cell type:markdown id:0001-0bebc6b6eb83092be697185a2599a6f69e7e1b9671b6d5d4a518b5703f1 tags:
# Vergleichsoperatoren
Vergleiche die unten gegebenen Zahlen mit den Vergleichsoperatoren (`<`,
`<=`, `==`, `>=`, `>`, `!=`, `is`, `in`). Gib die Ergebnisse aus sowie
und die Operationen.
%% Cell type:code id:0002-447284fe2410e1374b11eda2a62c1b5cc2e19091abf8913348661b99806 tags:
```
a = 8
b = 8
```
%% Cell type:markdown id:0013-2f78de72bdc2ed991ada865deddb160caf8d99da0f149b3c5d343526431 tags:
## Lösung
``` python
print(a, "<", b, ":", a < b)
```
8 < 8 : False
``` python
print(a, "<=", b, ":", a <= b)
```
8 <= 8 : True
``` python
print(a, "==", b, ":", a == b)
```
8 == 8 : True
``` python
print(a, ">=", b, ":", a >= b)
```
8 >= 8 : True
``` python
print(a, ">", b, ":", a > b)
```
8 > 8 : False
``` python
print(a, "!=", b, ":", a != b)
```
8 != 8 : False
``` python
print(a, "is", b, ":", a is b)
```
8 is 8 : True
``` python
print(a, "is not", b, ":", a is not b)
```
8 is not 8 : False
``` python
print(a, "in", [a, b], ":", a in [a, b])
```
8 in [8, 8] : True
``` python
print(a, "not in", [a, b], ":", a not in [a, b])
```
8 not in [8, 8] : False
%% Cell type:markdown id:0001-0bebc6b6eb83092be697185a2599a6f69e7e1b9671b6d5d4a518b5703f1 tags:
# Vergleichsoperatoren
Vergleiche die unten gegebenen Zahlen mit den Vergleichsoperatoren (`<`,
`<=`, `==`, `>=`, `>`, `!=`, `is`, `in`). Gib die Ergebnisse aus sowie
und die Operationen.
%% Cell type:code id:0002-447284fe2410e1374b11eda2a62c1b5cc2e19091abf8913348661b99806 tags:
```
a = 8
b = 8
```
%% Cell type:markdown id:0003-4f90926ab6960e65168fdff6f5e151194200dd69b468fb4eeb302fa84f1 tags:
Hier Ihr Code:
%% Cell type:code id:0004-44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 tags:
```
```
%% Cell type:markdown id:0001-faf463953b9917c64d08b624a64beac7f9a7e85dee1dea502c037dfe81e tags:
# Vergleich von floats
Vergleiche die unten gegebene Gleitkommazahlen unter Berücksichtigung
einer Toleranz.
%% Cell type:code id:0002-07d9a6cf6e59416ab6fc5dcb511d377465445d6287ea969f634fa82078e tags:
```
abstol = 1e-6
a = 0.1
b = 0.2
```
%% Cell type:markdown id:0007-1ad301ac4e464ec8d5f899f529f33cff5b7d81557b51ff2121909c02b2e tags:
## Lösung
``` python
abstol = 1e-6
a = 0.1
b = 0.2
```
``` python
abs(a - b) < abstol # Prüfen, ob der Unterschied nahezu null ist
```
False
``` python
abs(a - b) > abstol
```
True
Die Zahlen sind nicht nahezu gleich.
%% Cell type:markdown id:0001-faf463953b9917c64d08b624a64beac7f9a7e85dee1dea502c037dfe81e tags:
# Vergleich von floats
Vergleiche die unten gegebene Gleitkommazahlen unter Berücksichtigung
einer Toleranz.
%% Cell type:code id:0002-07d9a6cf6e59416ab6fc5dcb511d377465445d6287ea969f634fa82078e tags:
```
abstol = 1e-6
a = 0.1
b = 0.2
```
%% Cell type:markdown id:0003-4f90926ab6960e65168fdff6f5e151194200dd69b468fb4eeb302fa84f1 tags:
Hier Ihr Code:
%% Cell type:code id:0004-44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 tags:
```
```
%% Cell type:markdown id:0001-1ac6752a39fc633e2c03e5901c3d5e346f33be7596dd887ab30fc54b8c8 tags:
# Verknüpfungsoperatoren
Wende logische Verknüpfungen (`and`, `or`, `not`) auf die unten
gegebenen booleschen Werte an. Gib die Ergebnisse aus und bennene die
Operationen.
%% Cell type:code id:0002-cb568ae02004a3988c5c6ca30abac924b1d1fbe48efcd0ee6d171da480f tags:
```
wert1 = True
wert2 = False
```
%% Cell type:markdown id:0008-97671f9abcb165c0d76c915fb51300d19de3735a7cdf137351a972f5fa6 tags:
## Lösung
``` python
ergebnis_and = wert1 and wert2 # Logische AND-Verknüpfung
ergebnis_or = wert1 or wert2 # Logische OR-Verknüpfung
ergebnis_not_wert1 = not wert1 # Logische Negation von Wert 1
ergebnis_not_wert2 = not wert2 # Logische Negation von Wert 2
```
``` python
print("Ergebnis von AND:", ergebnis_and)
```
Ergebnis von AND: False
``` python
print("Ergebnis von OR:", ergebnis_or)
```
Ergebnis von OR: True
``` python
print("Ergebnis von NOT für Wert 1:", ergebnis_not_wert1)
```
Ergebnis von NOT für Wert 1: False
``` python
print("Ergebnis von NOT für Wert 2:", ergebnis_not_wert2)
```
Ergebnis von NOT für Wert 2: True
%% Cell type:markdown id:0001-1ac6752a39fc633e2c03e5901c3d5e346f33be7596dd887ab30fc54b8c8 tags:
# Verknüpfungsoperatoren
Wende logische Verknüpfungen (`and`, `or`, `not`) auf die unten
gegebenen booleschen Werte an. Gib die Ergebnisse aus und bennene die
Operationen.
%% Cell type:code id:0002-cb568ae02004a3988c5c6ca30abac924b1d1fbe48efcd0ee6d171da480f tags:
```
wert1 = True
wert2 = False
```
%% Cell type:markdown id:0003-4f90926ab6960e65168fdff6f5e151194200dd69b468fb4eeb302fa84f1 tags:
Hier Ihr Code:
%% Cell type:code id:0004-44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 tags:
```
```
%% Cell type:markdown id:0001-4bc200ca3692f2ebceba9577d4445757a1214a876a5b5202c4d386b1234 tags:
# Prioritäten
Überprüfe das Ergebnis von folgenden Ausdrücken. Beachte die
Operatorprioritäten.
%% Cell type:code id:0002-4678a47dd4cc1e476372f64aecb8fe507fa58cbba4659669a08a4500d80 tags:
```
ergebnis = 3 + 5 * 2
ergebnis2 = (3 + 5) * 2
```
%% Cell type:markdown id:0007-c9e0cd1ce26ce7e777aa434d0b729b6fb80ac73f1a4b49b258e26eae524 tags:
## Lösung
Hier wird wegen höherer Operatorpriorität die Multiplikation vor der
Addition ausgeführt:
``` python
ergebnis = 3 + 5 * 2
print("Ergebnis:", ergebnis)
```
Ergebnis: 13
Durch die Klammern wird die Addition zuerst berechnet:
``` python
ergebnis2 = (3 + 5) * 2
print("Ergebnis2:", ergebnis2)
```
Ergebnis2: 16
%% Cell type:markdown id:0001-4bc200ca3692f2ebceba9577d4445757a1214a876a5b5202c4d386b1234 tags:
# Prioritäten
Überprüfe das Ergebnis von folgenden Ausdrücken. Beachte die
Operatorprioritäten.
%% Cell type:code id:0002-4678a47dd4cc1e476372f64aecb8fe507fa58cbba4659669a08a4500d80 tags:
```
ergebnis = 3 + 5 * 2
ergebnis2 = (3 + 5) * 2
```
%% Cell type:markdown id:0003-4f90926ab6960e65168fdff6f5e151194200dd69b468fb4eeb302fa84f1 tags:
Hier Ihr Code:
%% Cell type:code id:0004-44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 tags:
```
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment