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

Notebooks from ckaufmann/akis-python-framework@c7384d48

parent f775bde3
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:0005-8eb736fd54ed821975c03a16c39231ddccf05ddfd1f695c6df94bbc2877 tags: %% Cell type:markdown id:0005-8eb736fd54ed821975c03a16c39231ddccf05ddfd1f695c6df94bbc2877 tags:
# Fläche und Umfang eines Kreises # Fläche und Umfang eines Kreises
Schreiben Sie eine Funktion `kreis`, die den Radius eines Kreises Schreiben Sie eine Funktion `kreis`, die den Radius eines Kreises
übergeben bekommt. Die Funktion soll die den Flächeninhalt und den übergeben bekommt. Die Funktion soll die den Flächeninhalt und den
Umfang zurück geben. Testen Sie ihre Funktion, indem Sie die Funktion Umfang zurück geben. Testen Sie ihre Funktion, indem Sie die Funktion
aufrufen und beide Rückgabewerte einzeln ausgeben. aufrufen und beide Rückgabewerte einzeln ausgeben.
*Hinweis: Die Konstante $\pi$ können Sie auf zwei Arten als `pi` *Hinweis: Die Konstante $\pi$ können Sie auf zwei Arten als `pi`
importieren:* importieren:*
- `from math import pi` - `from math import pi`
- `from numpy import pi` - `from numpy import pi`
## Lösung ## Lösung
Die Fläche eines Kreises ist $a = \pi · r^2$. Der Umfang eines Kreises Die Fläche eines Kreises ist $a = \pi · r^2$. Der Umfang eines Kreises
ist $p = 2 · \pi · r$. Die Funktion muss also wie folgt aussehen: ist $p = 2 · \pi · r$. Die Funktion muss also wie folgt aussehen:
%% Cell type:code id:0006-8a4072981d3849089a57c1035af2196faea238c016a8dd6199a587dff1b tags: %% Cell type:code id:0006-8a4072981d3849089a57c1035af2196faea238c016a8dd6199a587dff1b tags:
``` ```
def kreis(radius): def kreis(radius):
from math import pi from math import pi
area = pi * radius**2 area = pi * radius**2
perimeter = 2 * pi * radius perimeter = 2 * pi * radius
return area, perimeter return area, perimeter
``` ```
%% Cell type:code id:0007-314184afe68554751c7be4e5c1d3869239904f6387804556655fb86f36e tags: %% Cell type:code id:0007-3b6b3da3fe9a7f07555268a04ef491a59107c8470a875cc4a01d432af9c tags:
``` ```
a, p = kreis(2) a, p = kreis(2)
print('Fläche =', a) f'Fläche = {a}'
``` ```
%% Output %% Output
Fläche = 12.566370614359172 'Fläche = 12.566370614359172'
%% Cell type:code id:0008-3ce43a0e8c461119da67a8327e30ce2083d20bd59ee4635792578a34d2d tags: %% Cell type:code id:0008-3ce215e6fc995ede85579bf438743c42d45e695fca38d8f28a3ce631e8b tags:
``` ```
print('Umfang =', p) f'Umfang = {p}'
``` ```
%% Output %% Output
Umfang = 12.566370614359172 'Umfang = 12.566370614359172'
%% Cell type:markdown id:0009-372eb0d1de051c603302b93ade3cf670777fb8a6b5cf61edddc34915eba tags: %% Cell type:markdown id:0009-372eb0d1de051c603302b93ade3cf670777fb8a6b5cf61edddc34915eba tags:
## Tests ## Tests
%% Cell type:code id:0010-4ea26216dd150daa8aa32c2eb73f68b326ca887fe37ea8a307a28983f0e tags: %% Cell type:code id:0010-4ea26216dd150daa8aa32c2eb73f68b326ca887fe37ea8a307a28983f0e tags:
``` ```
a, p = kreis(4) a, p = kreis(4)
print(f'Fläche = {a:.2f}') print(f'Fläche = {a:.2f}')
``` ```
%% Output %% Output
Fläche = 50.27 Fläche = 50.27
%% Cell type:code id:0011-f9e4563bafc5a1597829e05bc456cd486620134933c2dc287d635206a9b tags: %% Cell type:code id:0011-f9e4563bafc5a1597829e05bc456cd486620134933c2dc287d635206a9b tags:
``` ```
print(f'Umfang = {p:.2f}') print(f'Umfang = {p:.2f}')
``` ```
%% Output %% Output
Umfang = 25.13 Umfang = 25.13
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment