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-06-06 07:35] hofgf_informatik:daten:processing [2025-06-06 08:29] (aktuell) – [Aufgabe 6] hof
Zeile 114: 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 120: 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 126: 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 142: Zeile 141:
 <nodisp 1> <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 162: Zeile 161:
  
 print("Smallest town: ", find_smallest_population()) print("Smallest town: ", find_smallest_population())
-</code>+</bottom-editor></html>
 ++++ ++++
 </nodisp> </nodisp>
Zeile 168: Zeile 167:
 <nodisp 1> <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 208: Zeile 187:
  
 print("Largest area", find_largest_area()) print("Largest area", find_largest_area())
-</code>+</bottom-editor></html>
 ++++ ++++
 </nodisp> </nodisp>
Zeile 220: Zeile 199:
 <nodisp 1> <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 274: Zeile 253:
 summarize_canton('TI') summarize_canton('TI')
 summarize_canton('GL') summarize_canton('GL')
-</code>+</bottom-editor></html>
 ++++ ++++
 </nodisp> </nodisp>
  • gf_informatik/daten/processing.1749195350.txt.gz
  • Zuletzt geändert: 2025-06-06 07:35
  • von hof