no way to compare when less than two revisions
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| — | de:modul:m319:learningunits:lu05:loesungen:factorial [2025/06/23 07:45] (aktuell) – ↷ Seite von modul:m319:learningunits:lu05:loesungen:factorial nach de:modul:m319:learningunits:lu05:loesungen:factorial verschoben msuter | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | ====== LU05.L11: Factorial ====== | ||
| + | |||
| + | <code python> | ||
| + | def main_while(): | ||
| + | iterations = int(input(' | ||
| + | count = 1 | ||
| + | fact = 1 | ||
| + | while count <= iterations: | ||
| + | fact = fact * count | ||
| + | count += 1 | ||
| + | print(fact) | ||
| + | |||
| + | |||
| + | def main_for(): | ||
| + | iterations = int(input(' | ||
| + | fact = 1 | ||
| + | for count in range(1, iterations + 1): # start from 1, and iterations+1 to ensure that upper bound is included | ||
| + | fact = fact * count | ||
| + | print(fact) | ||
| + | |||
| + | |||
| + | if __name__ == ' | ||
| + | main_while() | ||
| + | main_for() | ||
| + | |||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | {{tag> | ||
| + | [[https:// | ||