Benutzer-Werkzeuge

Webseiten-Werkzeuge


schule:programmieruebungen

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
schule:programmieruebungen [2019-12-22 10:42] – [Tic Tac Toe] added doctest marco.bakeraschule:programmieruebungen [2021-05-06 20:55] (aktuell) – [Links] elevator challenge: link zu py3 version pintman
Zeile 66: Zeile 66:
 --></html> --></html>
    
 +===== Testgetriebene Entwicklung (TDD) =====
 +
 +→ [[Testgetriebene Entwicklung (Übung)]]
 +
 +
 ===== Unterschiedliche Laufzeiten ===== ===== Unterschiedliche Laufzeiten =====
  
Zeile 203: Zeile 208:
  
 <file python ttt.py> <file python ttt.py>
 +'''
 +Auf diese Art kann die Klasse verwendet werden:
 +
 +>>> ttt = TicTacToe()
 +>>> ttt.stones
 +{}
 +>>> ttt.place_x_at(1,1)
 +>>> ttt.place_o_at(0,0)
 +>>> ttt.stones
 +{(1, 1): 'x', (0, 0): 'o'}
 +>>> ttt.x_wins()
 +False
 +>>> ttt.o_wins()
 +False
 +>>> ttt.place_x_at(0,1)
 +>>> ttt.place_o_at(1,0)
 +>>> ttt.place_x_at(2,1)
 +>>> ttt.x_wins()
 +True
 +>>> ttt.o_wins()
 +False
 +>>> ttt.stones
 +{(1, 1): 'x', (0, 0): 'o', (0, 1): 'x', (1, 0): 'o', (2, 1): 'x'}
 +'''
 +
 import doctest import doctest
  
 class TicTacToe: class TicTacToe:
-    '''A game of tic tac toe. +    'A game of tic tac toe.'
-     +
-    >>> ttt = TicTacToe() +
-    >>> ttt.stones +
-    {} +
-    >>> ttt.place_x_at(1,1) +
-    >>> ttt.place_o_at(0,0) +
-    >>> ttt.stones +
-    {(1, 1): 'x', (0, 0): 'o'+
-    >>> ttt.x_wins() +
-    False +
-    >>> ttt.o_wins() +
-    False +
-    >>> ttt.place_x_at(0,1) +
-    >>> ttt.place_o_at(1,0) +
-    >>> ttt.place_x_at(2,1) +
-    >>> ttt.x_wins() +
-    True +
-    >>> ttt.o_wins() +
-    False +
-    >>> ttt.stones +
-    {(1, 1): 'x', (0, 0): 'o', (0, 1): 'x', (1, 0): 'o', (2, 1): 'x'+
-    '''+
  
     def __init__(self):     def __init__(self):
Zeile 235: Zeile 243:
  
     def place_x_at(self, x, y):     def place_x_at(self, x, y):
 +        assert 0 <= x <= 2 and 0 <= y <= 2
         self.stones[(x, y)] = "x"         self.stones[(x, y)] = "x"
  
     def place_o_at(self, x, y):     def place_o_at(self, x, y):
 +        assert 0 <= x <= 2 and 0 <= y <= 2
         self.stones[(x, y)] = "o"         self.stones[(x, y)] = "o"
  
Zeile 267: Zeile 277:
  
 <html><!-- <html><!--
 +'''
 +Auf diese Art kann die Klasse verwendet werden:
 +
 +>>> ttt = TicTacToe()
 +>>> ttt.stones
 +{}
 +>>> ttt.place_x_at(1,1)
 +>>> ttt.place_o_at(0,0)
 +>>> ttt.stones
 +{(1, 1): 'x', (0, 0): 'o'}
 +>>> ttt.x_wins()
 +False
 +>>> ttt.o_wins()
 +False
 +>>> ttt.place_x_at(0,1)
 +>>> ttt.place_o_at(1,0)
 +>>> ttt.place_x_at(2,1)
 +>>> ttt.x_wins()
 +True
 +>>> ttt.o_wins()
 +False
 +>>> ttt.stones
 +{(1, 1): 'x', (0, 0): 'o', (0, 1): 'x', (1, 0): 'o', (2, 1): 'x'}
 +'''
 +
 import doctest import doctest
  
 class TicTacToe: class TicTacToe:
-    '''A game of tic tac toe. +    'A game of tic tac toe.'
-     +
-    >>> ttt = TicTacToe() +
-    >>> ttt.stones +
-    {} +
-    >>> ttt.place_x_at(1,1) +
-    >>> ttt.place_o_at(0,0) +
-    >>> ttt.stones +
-    {(1, 1): 'x', (0, 0): 'o'+
-    >>> ttt.x_wins() +
-    False +
-    >>> ttt.o_wins() +
-    False +
-    >>> ttt.place_x_at(0,1) +
-    >>> ttt.place_o_at(1,0) +
-    >>> ttt.place_x_at(2,1) +
-    >>> ttt.x_wins() +
-    True +
-    >>> ttt.o_wins() +
-    False +
-    >>> ttt.stones +
-    {(1, 1): 'x', (0, 0): 'o', (0, 1): 'x', (1, 0): 'o', (2, 1): 'x'+
-    '''+
  
     def __init__(self):     def __init__(self):
Zeile 299: Zeile 312:
  
     def place_x_at(self, x, y):     def place_x_at(self, x, y):
 +        assert 0 <= x <= 2 and 0 <= y <= 2
         self.stones[(x, y)] = "x"         self.stones[(x, y)] = "x"
  
     def place_o_at(self, x, y):     def place_o_at(self, x, y):
 +        assert 0 <= x <= 2 and 0 <= y <= 2
         self.stones[(x, y)] = "o"         self.stones[(x, y)] = "o"
  
Zeile 356: Zeile 371:
 ===== Programm, das den eigenen Quelltext ausgibt ===== ===== Programm, das den eigenen Quelltext ausgibt =====
  
-Schreibe ein Programm, das den eigenen Quelltext ausgibt. Dabei darf nicht auf Dateioperationen zurückgegriffen werden. Sonst wäre es zu einfach. Dann könnte man einfach nur die Datei ausgeben, die den Quelltext enthält.+→ [[Eigenen Quelltext ausgeben]]
  
-Das schöne an dieser Aufgabenstellung ist, dass sie zunächst sehr einfach und nach ein paar Versuchen faktisch unmöglich erscheint.  
  
-Versuche dich selbst an einem [[Python]]-Programm, das den eigenen Quelltext ausgibt. 
- 
-Wenn du keinen Ansatz findest, kann du den (unvollständigen) Quelltext aus der Fußnote(( 
-<code python> 
-source = [ 
-    'print("source = [")', 
-    ... 
-] 
- 
-print("source = [") 
-for line in source:   
-    print(line, ",") 
-... 
- 
-</code> 
-)) nutzen. 
  
 ===== Katas im Randori-Prinzip ===== ===== Katas im Randori-Prinzip =====
Zeile 393: Zeile 391:
 ===== Links ===== ===== Links =====
  
 +  * Hinter einem [[wpde>Kata (Programmierung)|Kata]] verbirgt sich in der Programmierung eine kleine, abgeschlossene Übung. [[http://codekata.com/|CodeKata]] versammelt eine Reihe interessanter Übungen.
   * [[https://www.practicepython.org/|Practice Python]] enthält verschiedene Übungen für Anfänger.   * [[https://www.practicepython.org/|Practice Python]] enthält verschiedene Übungen für Anfänger.
   * Weitere Übungen zur OOP mit Python gibt es [[https://www.inf-schule.de/modellierung/ooppython/bank/objekteklassen/uebungen|hier]].   * Weitere Übungen zur OOP mit Python gibt es [[https://www.inf-schule.de/modellierung/ooppython/bank/objekteklassen/uebungen|hier]].
Zeile 402: Zeile 401:
   * [[Flagserver]]   * [[Flagserver]]
   * [[https://blog.bakera.de/ein-programm-das-den-eigenen-quelltext-ausgibt.html|Programm, welches den eigenen Quelltext ausgibt]]   * [[https://blog.bakera.de/ein-programm-das-den-eigenen-quelltext-ausgibt.html|Programm, welches den eigenen Quelltext ausgibt]]
 +  * Bei der [[https://github.com/pintman/python-elevator-challenge|Python Elevator Challenge]] muss ein Aufzug in [[Python]] programmiert werden.
 +
 +
schule/programmieruebungen.1577007759.txt.gz · Zuletzt geändert: 2019-12-22 10:42 von marco.bakera