- Computer Grundlagen III: Algorithmen
- Python Grundlagen III: Funktionen & Bibliotheken
- Projekt 3: Web-APIs und Spreadsheets
- Quellen zum Selbststudium
>>> def maximum(a, b):
... if a > b:
... return a
... else:
... return b
...
>>> maximum(5,6)
6
def maximum(a, b):
if a > b:
return a
else:
return b
from maximum import maximum
print(maximum(7,8))
$ python3 programm.py
8
>>> import matplotlib.pyplot as plt
>>> x = range(1,10)
>>> fig, ax = plt.subplots()
>>> ax.plot(x, x)
[]
>>> plt.show()
$ python3 -m venv venv
$ source venv/bin/activate | venv\Scripts\activate.bat
$ pip install requests
>>> import requests
>>> r = requests.get('https://api.chucknorris.io/jokes/random')
>>> if r.status_code != 200:
... print('Fehler!')
... else:
... json = r.json()
... print(json['value'])
...
jesus did not make Chuck Norris, Chuck Norris made jesus
import requests
r = requests.get('https://api.ipify.org?format=json')
if r.status_code != 200:
print('Fehler!')
else:
json = r.json()
print(f"Die IP ist: {json['ip']}")
$ python teil1_1.py
Die IP ist: 84.39.77.83
...
geo_url = f'https://ipinfo.io/{ip}/geo'
r = requests.get(geo_url)
if r.status_code != 200:
print('Fehler, Geo-Daten konnten nicht ermittelt werden!')
sys.exit(1)
json = r.json()
print(f"Land: {json['country']}\nStadt: {json['city']}\nISP: {json['org']}")
$ python teil1_2.py
Die IP ist: 84.39.77.83
Land: DE
Stadt: Neumarkt in der Oberpfalz
ISP: AS39090 Brandl Services GmbH
>>> from openpyxl import load_workbook
>>> wb = load_workbook(filename = 'Employee Sample Data.xlsx')
>>> ws = wb.active
>>> spalten = [chr(x) for x in range(ord('A'), ord('N'))]
>>> for s in spalten:
... print(ws[f'{s}1'].value)
...
EEID
Full Name
Job Title
...
>>> from collections import OrderedDict
>>> from pyexcel_ods import save_data
>>> data = OrderedDict()
>>> data.update({"Meine Daten": [[1, 2, 3], [4, 5, 6]]})
>>> save_data("meien_daten.ods", data)
from openpyxl import load_workbook
wb = load_workbook(filename = 'Employee Sample Data.xlsx')
ws = wb.active
i = 2
sum = 0
count = 0
while ws[f'A{i}'].value:
if ws[f'N{i}'].value == '':
count = count + 1
sum = sum + ws[f'J{i}'].value
i = i + 1
print("Durchschnittsverdienst: ${:0,.2f}".format(sum/count))
$ python teil2.py
Durchschnittsverdienst: $114,033.07
...
from collections import OrderedDict
from pyexcel_ods import save_data
zeilen = [['Name', 'Berufstitel']]
i = 2
while ws[f'A{i}'].value:
if ws[f'N{i}'].value == '':
zeilen.append([ws[f'B{i}'].value, ws[f'C{i}'].value])
i = i + 1
data = OrderedDict()
data.update({"Angestellte": zeilen})
save_data("angestellte.ods", data)
Bringt eure eigenen Projekte an Tag 4 mit!
Was könnt ihr für euren Alltag brauchen?