no way to compare when less than two revisions
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| — | de:modul:m319:learningunits:lu05:loesungen:splitinpieces [2025/06/23 07:45] (aktuell) – ↷ Seite von modul:m319:learningunits:lu05:loesungen:splitinpieces nach de:modul:m319:learningunits:lu05:loesungen:splitinpieces verschoben msuter | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | ====== LU05.L12: Split in pieces ====== | ||
| + | |||
| + | ===== 1. Einlesen ===== | ||
| + | |||
| + | <code python> | ||
| + | def main(): | ||
| + | print(' | ||
| + | number = 1 # To compensate for -1 for terminating | ||
| + | while number != -1: | ||
| + | number = int(input()) | ||
| + | print(' | ||
| + | |||
| + | |||
| + | if __name__ == ' | ||
| + | main() | ||
| + | </ | ||
| + | |||
| + | ===== 2. Summe der Zahlen ===== | ||
| + | <code python> | ||
| + | def main(): | ||
| + | print(' | ||
| + | number = 0 | ||
| + | sums = 1 # To compensate for -1 for terminating | ||
| + | while number != -1: | ||
| + | number = int(input('' | ||
| + | sums += number | ||
| + | print(' | ||
| + | print(f' | ||
| + | |||
| + | |||
| + | if __name__ == ' | ||
| + | main() | ||
| + | </ | ||
| + | |||
| + | ===== 3. Summe und die Anzahl der Zahlen ===== | ||
| + | <code python> | ||
| + | def main(): | ||
| + | print(' | ||
| + | number = 0 | ||
| + | sums = 1 # To compensate for -1 for terminating | ||
| + | counter = -1 # We start with -1 to compensate for last iteration | ||
| + | while number != -1: | ||
| + | number = int(input('' | ||
| + | sums += number | ||
| + | counter += 1 | ||
| + | print(' | ||
| + | print(f' | ||
| + | print(f' | ||
| + | |||
| + | |||
| + | if __name__ == ' | ||
| + | main() | ||
| + | </ | ||
| + | |||
| + | ===== 4. Durchschnitt der Zahlen ===== | ||
| + | <code python> | ||
| + | def main(): | ||
| + | print(' | ||
| + | number = 0 | ||
| + | sums = 1 # To compensate for -1 for terminating | ||
| + | counter = -1 # We start with -1 to compensate for last iteration | ||
| + | while number != -1: | ||
| + | number = int(input('' | ||
| + | sums += number | ||
| + | counter += 1 | ||
| + | print(' | ||
| + | print(f' | ||
| + | print(f' | ||
| + | average = sums / counter | ||
| + | print(f' | ||
| + | |||
| + | |||
| + | if __name__ == ' | ||
| + | main() | ||
| + | </ | ||
| + | |||
| + | ===== 5. Gerade und ungerade Zahlen ===== | ||
| + | <code python> | ||
| + | def main(): | ||
| + | print(' | ||
| + | number = 0 | ||
| + | sums = 1 # To compensate for -1 for terminating | ||
| + | counter = -1 # We start with -1 to compensate for last iteration | ||
| + | odd = 0 | ||
| + | even = 0 | ||
| + | while number != -1: | ||
| + | number = int(input('' | ||
| + | if (number % 2 == 0 and number != -1): | ||
| + | even += 1 | ||
| + | if (number % 2 == 1 and number != -1): | ||
| + | odd += 1 | ||
| + | sums += number | ||
| + | counter += 1 | ||
| + | print(' | ||
| + | print(f' | ||
| + | print(f' | ||
| + | average = sums / counter | ||
| + | print(f' | ||
| + | print(f' | ||
| + | print(f' | ||
| + | |||
| + | |||
| + | if __name__ == ' | ||
| + | main() | ||
| + | |||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | {{tag> | ||
| + | [[https:// | ||