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

Notebooks from applied-cs/data-science@357ef879

parent 9f7d724a
Branches
Tags
No related merge requests found
%% Cell type:markdown id:0002-e5636d533a5cf2340aa871080057bd0db4a75a13e0e96e322df313d3a5c tags:
# Zungenbrecher
Erstelle nur per Slicing von `s` und String-Konkatenation den
Zungebrecher
Fischers Fritze fischte frische Fische,
frische Fische fischte Fischers Fritze.
%% Cell type:code id:0003-dfa61d0c4ca30af9c3e1cb18392ce695c1deb817b410d0b5e85fe5b70c6 tags:
```
# 0000000000111111111122222222223
# 0123456789012345678901234567890
s = ' FischersFritzefischtefrische,.'
```
%% Cell type:markdown id:0004-94702981911ec4f24f72794f610c502911e5197963070b964d3f3c40038 tags:
## Lösung
%% Cell type:code id:0005-346a28deeca603d3a2807a188c261e6b0fee65697dcb44ac0a217f1340b tags:
```
# Fischers Fritze fischte frische Fische ,
print(s[1:9] + s[0] + s[9:15] + s[0] + s[15:22] + s[0] + s[22:29] + s[0] + s[1:7] + s[-2])
```
%% Output
Fischers Fritze fischte frische Fische,
%% Cell type:code id:0006-b24e02d1a6efc4cb41c4206ba1ff7320ae29717b380670138043192e38c tags:
```
# frische Fische fischte Fischers Fritze .
print(s[22:29] + s[0] + s[1:7] + s[0] + s[15:22] + s[0] + s[1:9] + s[0] + s[9:15] + s[-1])
```
%% Output
frische Fische fischte Fischers Fritze.
%% Cell type:markdown id:0002-e5636d533a5cf2340aa871080057bd0db4a75a13e0e96e322df313d3a5c tags:
# Zungenbrecher
Erstelle nur per Slicing von `s` und String-Konkatenation den
Zungebrecher
Fischers Fritze fischte frische Fische,
frische Fische fischte Fischers Fritze.
%% Cell type:code id:0003-dfa61d0c4ca30af9c3e1cb18392ce695c1deb817b410d0b5e85fe5b70c6 tags:
```
# 0000000000111111111122222222223
# 0123456789012345678901234567890
s = ' FischersFritzefischtefrische,.'
```
%% Cell type:markdown id:0004-4f90926ab6960e65168fdff6f5e151194200dd69b468fb4eeb302fa84f1 tags:
Hier Ihr Code:
%% Cell type:code id:0005-44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 tags:
```
```
%% Cell type:markdown id:0001-dbe1bee56c4e63a06a057e911b637c6b15c0bf7ef109fca6d88acba2ef3 tags:
# Echo
Probieren Sie folgenden Code aus:
%% Cell type:code id:0002-ad68d7f641b224938985231bc6472ce0e8828594480e325120c9cef5832 tags:
```
while True:
prompt = input('> ')
if prompt == 'exit':
break
print(prompt)
```
%% Cell type:markdown id:0001-9b79ff280fe04a12b77d5a311ffb6e7df4dbbb9137b5bfbf6ebb4bd2bf3 tags:
# Timestamp Print
Schreiben Sie eine Funktion `ts_print`, die beliebig viele unbenannte
und benannte Argumente übergeben bekommt. Die Funktion soll dann den
aktuellen Timestamp am Anfang der Zeile ausgeben und dahinter die
Ausgabe von `print` mit den weitergeleiteten unbenannten und benannten
Argumenten.
%% Cell type:code id:0002-491ba4deee622e6c29ca383c71279fa604b7aff389b0bf5ba279f4453c3 tags:
```
import time
```
%% Cell type:markdown id:0004-05417a0efa062082cdcefdbf02027ae8284abeb12312550d92c50409cc7 tags:
## Lösung
Für beliebig viele unbenannte Argumente wird die `*args`-Notation und
für beliebig viele benannte Argumente wird die `**kwargs`-Notation
benötigt. Diese werden einfach nach dem ersten Argument `time.ctime()`
an `print` per Unpacking übergeben:
%% Cell type:code id:0005-413982a243e0196d8a9a28a7d85f86ff0f45af2192d4812d0e60c49eaae tags:
```
import time
def ts_print(*args, **kwargs):
print(time.ctime(), *args, **kwargs)
```
%% Cell type:markdown id:0007-ad823fe81dde0bf12988334ada9c5afc65bde4a572cd9e560fde1ac4411 tags:
## Tests
Hier ein paar Checks:
%% Cell type:code id:0008-ee36640fe2bfbf2f52416f26a3ba7e920b8555718948e9c8c09b7b43475 tags:
```
ts_print('This is a test')
```
%% Output
Tue Jan 19 03:14:07 2038 This is a test
%% Cell type:code id:0009-1ef343c7a98589898fe8f073873268a23eaff397ef4570b5616ff762d35 tags:
```
ts_print(4, 3, 2, 1, sep=' > ')
```
%% Output
Tue Jan 19 03:14:07 2038 > 4 > 3 > 2 > 1
%% Cell type:markdown id:0001-9b79ff280fe04a12b77d5a311ffb6e7df4dbbb9137b5bfbf6ebb4bd2bf3 tags:
# Timestamp Print
Schreiben Sie eine Funktion `ts_print`, die beliebig viele unbenannte
und benannte Argumente übergeben bekommt. Die Funktion soll dann den
aktuellen Timestamp am Anfang der Zeile ausgeben und dahinter die
Ausgabe von `print` mit den weitergeleiteten unbenannten und benannten
Argumenten.
%% Cell type:code id:0002-491ba4deee622e6c29ca383c71279fa604b7aff389b0bf5ba279f4453c3 tags:
```
import time
```
%% Cell type:markdown id:0004-ad823fe81dde0bf12988334ada9c5afc65bde4a572cd9e560fde1ac4411 tags:
## Tests
Hier ein paar Checks:
%% Cell type:code id:0005-ee36640fe2bfbf2f52416f26a3ba7e920b8555718948e9c8c09b7b43475 tags:
```
ts_print('This is a test')
```
%% Output
Tue Jan 19 03:14:07 2038 This is a test
%% Cell type:code id:0006-1ef343c7a98589898fe8f073873268a23eaff397ef4570b5616ff762d35 tags:
```
ts_print(4, 3, 2, 1, sep=' > ')
```
%% Output
Tue Jan 19 03:14:07 2038 > 4 > 3 > 2 > 1
Source diff could not be displayed: it is too large. Options to address this: view the blob.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment