no way to compare when less than two revisions
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| — | de:modul:m319:learningunits:lu14:loesungen:schachuhr [2025/06/23 07:45] (aktuell) – ↷ Seite von modul:m319:learningunits:lu14:loesungen:schachuhr nach de:modul:m319:learningunits:lu14:loesungen:schachuhr verschoben msuter | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | ====== LU15.L02 - Schachuhr ====== | ||
| + | ===== Lösungsschritte ===== | ||
| + | ==== 1. Entertaste ==== | ||
| + | <WRAP center round box 60%> | ||
| + | <code python> | ||
| + | |||
| + | | ||
| + | def chessclock(): | ||
| + | while True: | ||
| + | ins = input() | ||
| + | if ins == '': | ||
| + | print(' | ||
| + | |||
| + | |||
| + | if __name__ == ' | ||
| + | chessclock() | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== 2. Aktuelle Zeit ==== | ||
| + | |||
| + | <WRAP center round box 60%> | ||
| + | <code python> | ||
| + | from datetime import datetime, timedelta | ||
| + | |||
| + | def chessclock(): | ||
| + | |||
| + | print(' | ||
| + | input() | ||
| + | time_start = datetime.now() | ||
| + | |||
| + | while True: | ||
| + | ins = input() | ||
| + | if ins == '': | ||
| + | time_end = datetime.now() | ||
| + | dt = time_end - time_start | ||
| + | delta = timedelta(seconds=dt.seconds) | ||
| + | print(f' | ||
| + | |||
| + | |||
| + | if __name__ == ' | ||
| + | chessclock() | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ==== 3. Umbauen für 2 Personen ==== | ||
| + | |||
| + | 1 Printe: '[Für Start Enter drücken]' | ||
| + | 2 Lese input | ||
| + | 3 Speichere die aktuell Uhrzeit in eine Variable '' | ||
| + | 4 Printe: ' | ||
| + | 5 Variable '' | ||
| + | 6 Variable '' | ||
| + | 7 Variable '' | ||
| + | 8 Start endlosschleife | ||
| + | 8.1 Lese input | ||
| + | 8.2 Wenn input == '' | ||
| + | 8.2.1 Speichere die Uhrzeit in eine neue Variable '' | ||
| + | 8.2.2 Ziehe die Uhrzeit '' | ||
| + | 8.2.3 Speichere den Wert in eine Variable vom Typ '' | ||
| + | 8.2.4 Wenn der aktuelle Player ' | ||
| + | 8.2.4.1 Die Playtime zur Spielzeit von A addieren | ||
| + | 8.2.4.2 Den aktuellen Spieler auf Spieler B setzen | ||
| + | 8.2.5 Sonst | ||
| + | 8.2.5.1 Die Playtime zur Spielzeit von B addieren | ||
| + | 8.2.5.2 Den aktuellen Spieler auf Spieler A setzen | ||
| + | 8.2.6 Die '' | ||
| + | 8.2.7 Printe: ('Zeit Spieler A: ' + str(time_A)) | ||
| + | 8.2.8 Printe: ('Zeit Spieler B: ' + str(time_B)) | ||
| + | 8.2.9 Printe: (' | ||
| + | | ||
| + | <WRAP center round box 60%> | ||
| + | <code python> | ||
| + | from datetime import datetime, timedelta | ||
| + | |||
| + | def chessclock(): | ||
| + | time_A = timedelta() | ||
| + | time_B = timedelta() | ||
| + | actual_player = ' | ||
| + | |||
| + | print(' | ||
| + | input() | ||
| + | print(' | ||
| + | time_start = datetime.now() | ||
| + | |||
| + | while True: | ||
| + | ins = input() | ||
| + | if ins == '': | ||
| + | time_end = datetime.now() | ||
| + | dt = time_end - time_start | ||
| + | playtime = timedelta(seconds=dt.seconds) | ||
| + | if actual_player == ' | ||
| + | time_A += playtime | ||
| + | actual_player = ' | ||
| + | else: | ||
| + | time_B += playtime | ||
| + | actual_player = ' | ||
| + | time_start = datetime.now() | ||
| + | print(' | ||
| + | print(' | ||
| + | print(' | ||
| + | |||
| + | if __name__ == ' | ||
| + | chessclock() | ||
| + | </ | ||
| + | </ | ||