Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.

Link zu der Vergleichsansicht

Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung
Nächste Überarbeitung
Vorherige Überarbeitung
gf_informatik:daten:processing [2025-05-19 07:55] hofgf_informatik:daten:processing [2025-06-06 08:29] (aktuell) – [Aufgabe 6] hof
Zeile 1: Zeile 1:
 # Data Processing in Python # Data Processing in Python
 +<html><script type="module" src="https://bottom.ch/ksr/ed/bottom-editor.js"></script></html>
  
 {{ :gf_informatik:daten:dataprocessing.pptx | Präsentation}} {{ :gf_informatik:daten:dataprocessing.pptx | Präsentation}}
Zeile 85: Zeile 86:
   * Wieviele Gemeinden gibt es im Kanton Thurgau? Wieviele im Kanton Bern?   * Wieviele Gemeinden gibt es im Kanton Thurgau? Wieviele im Kanton Bern?
  
-<nodisp 2>+<nodisp 1>
 ++++Lösung:| ++++Lösung:|
-<code python> +<html><bottom-editor zip='https://bottom.ch/ksr/py/files/2m.zip'>with open('gemeinden.csv', 'r') as infile:
-with open('gemeinden.csv', 'r') as infile:+
     be = 0     be = 0
     tg = 0     tg = 0
Zeile 100: Zeile 100:
     print("Bern", be)     print("Bern", be)
     print("Thurgau", tg)     print("Thurgau", tg)
-</code>+</bottom-editor></html> 
 ++++ ++++
 </nodisp> </nodisp>
Zeile 113: Zeile 114:
 Allerdings funktioniert das nur, wenn der String auch wirklich eine Zahl darstellt. Sonst wird eine *Exception* geworfen; wir können sie mit `try...except` auffangen: Allerdings funktioniert das nur, wenn der String auch wirklich eine Zahl darstellt. Sonst wird eine *Exception* geworfen; wir können sie mit `try...except` auffangen:
  
-<code python>+<html><bottom-editor>
 try: try:
     my_number = int("abc" # may throw an exception     my_number = int("abc" # may throw an exception
Zeile 119: Zeile 120:
 except ValueError: except ValueError:
     pass                    # executed if an exception was thrown     pass                    # executed if an exception was thrown
-</code>+</bottom-editor></html>
  
 #### Aufgabe 5 #### Aufgabe 5
Zeile 125: Zeile 126:
    * welche Spalten (Indices) gehören zu diesen Werten?    * welche Spalten (Indices) gehören zu diesen Werten?
    * verwendest du `int()` oder `float()`?    * verwendest du `int()` oder `float()`?
- 
  
 #### Aufgabe 6 #### Aufgabe 6
Zeile 139: Zeile 139:
 ++++ ++++
  
-<nodisp 2>+<nodisp 1>
 ++++Code:| ++++Code:|
-<code python>+<html><bottom-editor zip='https://bottom.ch/ksr/py/files/2m.zip'>
 def find_smallest_population(): def find_smallest_population():
     with open('gemeinden.csv') as towns:     with open('gemeinden.csv') as towns:
Zeile 161: Zeile 161:
  
 print("Smallest town: ", find_smallest_population()) print("Smallest town: ", find_smallest_population())
-</code>+</bottom-editor></html>
 ++++ ++++
 </nodisp> </nodisp>
  
-<nodisp 2>+<nodisp 1>
 ++++Code:| ++++Code:|
-<code python> +<html><bottom-editor zip='https://bottom.ch/ksr/py/files/2m.zip'>
-def find_smallest_population(): +
-    with open('gemeinden.csv') as towns: +
-        # Search for the smallest, so start out with a value larger than any expected. +
-        min_pop = 1000000 +
-        town = None +
-        for line in towns: +
-            cells = line.split(',') +
-            try: +
-                # Population is in the third column, and it is an integer. +
-                population = int(cells[2]) +
-                if population < min_pop: +
-                    # We found a town smaller than the currently known smallest. +
-                    min_pop = population +
-                    town = cells[0] +
-            except ValueError: +
-                pass +
-        return town, min_pop +
- +
-print("Smallest town: ", find_smallest_population()) +
 def find_largest_area(): def find_largest_area():
     with open('gemeinden.csv') as towns:     with open('gemeinden.csv') as towns:
Zeile 207: Zeile 187:
  
 print("Largest area", find_largest_area()) print("Largest area", find_largest_area())
-</code>+</bottom-editor></html>
 ++++ ++++
 </nodisp> </nodisp>
Zeile 217: Zeile 197:
   * Wieviele Gemeinden hat der Kanton Glarus?   * Wieviele Gemeinden hat der Kanton Glarus?
  
-<nodisp 2>+<nodisp 1>
 ++++Code:| ++++Code:|
-<code python>+<html><bottom-editor zip='https://bottom.ch/ksr/py/files/2m.zip'>
 def summarize_canton(canton): def summarize_canton(canton):
     with open('gemeinden.csv', 'r') as infile:     with open('gemeinden.csv', 'r') as infile:
Zeile 273: Zeile 253:
 summarize_canton('TI') summarize_canton('TI')
 summarize_canton('GL') summarize_canton('GL')
-</code>+</bottom-editor></html>
 ++++ ++++
 </nodisp> </nodisp>
  • gf_informatik/daten/processing.1747641352.txt.gz
  • Zuletzt geändert: 2025-05-19 07:55
  • von hof