Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
| de:modul:m319:learningunits:lu10:aufgaben:taschenrechner [2025/06/23 07:45] – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1 | de:modul:m319:learningunits:lu10:aufgaben:taschenrechner [2025/06/23 07:45] (aktuell) – ↷ Links angepasst, weil Seiten im Wiki verschoben wurden msuter | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | ====== LU10.A01 - Taschenrechner als Modul ====== | ||
| + | ===== Ausgangslage ===== | ||
| + | |||
| + | In der [[de: | ||
| + | |||
| + | <WRAP center round box 60%> | ||
| + | <file python calc.py> | ||
| + | import math | ||
| + | |||
| + | |||
| + | def add(num1, num2): | ||
| + | """ | ||
| + | Addition of two numbers | ||
| + | :param num1: number 1 for calculation | ||
| + | :param num2: number 2 for calculation | ||
| + | :return: result of calculation | ||
| + | """ | ||
| + | return num1 + num2 | ||
| + | |||
| + | |||
| + | def sub(num1, num2): | ||
| + | """ | ||
| + | Substracts two numbers | ||
| + | :param num1: number 1 for calculation | ||
| + | :param num2: number 2 for calculation | ||
| + | :return: result of calculation | ||
| + | """ | ||
| + | return num1 - num2 | ||
| + | |||
| + | |||
| + | def mul(num1, num2): | ||
| + | """ | ||
| + | multiply of two numbers | ||
| + | :param num1: number 1 for calculation | ||
| + | :param num2: number 2 for calculation | ||
| + | :return: result of calculation | ||
| + | """ | ||
| + | return num1 * num2 | ||
| + | |||
| + | |||
| + | def div(num1, num2): | ||
| + | """ | ||
| + | division of two numbers | ||
| + | :param num1: number 1 for calculation | ||
| + | :param num2: number 2 for calculation | ||
| + | :return: result of calculation | ||
| + | """ | ||
| + | return num1 / num2 | ||
| + | |||
| + | |||
| + | def pow(num1): | ||
| + | """ | ||
| + | Squares two numbers | ||
| + | :param num1: number to square | ||
| + | :return: result of calculation | ||
| + | """ | ||
| + | return num1 * num1 | ||
| + | |||
| + | |||
| + | def sqrt(num1): | ||
| + | """ | ||
| + | return the root of a number | ||
| + | :param num1: number to get the root of | ||
| + | :return: result of calculation | ||
| + | """ | ||
| + | return math.sqrt(num1) | ||
| + | |||
| + | |||
| + | def main(): | ||
| + | result_add = add(5, 5.5) | ||
| + | result_div = div(10, 3) | ||
| + | result_mul = mul(3, 3) | ||
| + | result_sub = sub(10, 4.4) | ||
| + | result_pow = pow(23) | ||
| + | result_sqrt = sqrt(81) | ||
| + | |||
| + | print(result_add) | ||
| + | print(result_div) | ||
| + | print(result_mul) | ||
| + | print(result_sub) | ||
| + | print(result_pow) | ||
| + | print(result_sqrt) | ||
| + | |||
| + | |||
| + | if __name__ == ' | ||
| + | main() | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ===== Aufgabe ===== | ||
| + | In dieser Aufgabe werden sie diesen Taschenrechner nun als Modul für ein neues Projekt einbinden. | ||
| + | Nehmen Sie dazu die Github-Classroom-Aufgabe an. | ||
| + | |||
| + | ==== Teilaufgabe 1 ==== | ||
| + | |||
| + | Erstellen Sie das File '' | ||
| + | <WRAP center round important 60%> | ||
| + | Sie werden von PyCharm gefragt, ob Sie das File zu Git hinzufügen möchten. | ||
| + | Klicken Sie auf **Add** | ||
| + | |||
| + | {{de: | ||
| + | </ | ||
| + | |||
| + | und ergänzen Sie den [[de: | ||
| + | |||
| + | |||
| + | |||
| + | Passen Sie '' | ||
| + | |||
| + | <WRAP center round box 60%> | ||
| + | <code python> | ||
| + | #Add import statement for calc | ||
| + | |||
| + | def main(): | ||
| + | print(calc.add(5, | ||
| + | print(calc.mul(5, | ||
| + | |||
| + | |||
| + | if __name__ == ' | ||
| + | main() | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | Testen Sie die Implementierung mit '' | ||
| + | |||
| + | ==== Teilaufgabe 2 ==== | ||
| + | |||
| + | Importieren Sie das Modul '' | ||
| + | |||
| + | <WRAP center round box 60%> | ||
| + | <code python> | ||
| + | #Add import statement for calc | ||
| + | |||
| + | def main(): | ||
| + | print(c.add(5, | ||
| + | print(c.mul(5, | ||
| + | |||
| + | |||
| + | if __name__ == ' | ||
| + | main() | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | Testen Sie die Implementierung mit '' | ||
| + | |||
| + | ==== Teilaufgabe 3 ==== | ||
| + | |||
| + | Importieren Sie das Modul '' | ||
| + | |||
| + | <WRAP center round box 60%> | ||
| + | <code python> | ||
| + | #Add import statement for calc | ||
| + | |||
| + | def main(): | ||
| + | print(add(5, | ||
| + | print(mul(5, | ||
| + | |||
| + | if __name__ == ' | ||
| + | main() | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | Testen Sie die Implementierung mit '' | ||
| + | |||
| + | ==== Teilaufgabe 4 ==== | ||
| + | |||
| + | Importieren Sie '' | ||
| + | |||
| + | <WRAP center round box 60%> | ||
| + | <code python> | ||
| + | #Add import statement for add as addition and mul as multiplication from calc | ||
| + | |||
| + | def add(num1, num2): | ||
| + | ''' | ||
| + | Builds the sum of two numbers and prints the result | ||
| + | :param num1: first number | ||
| + | :param num2: second number | ||
| + | :return: None | ||
| + | ''' | ||
| + | print(num1 + num2) | ||
| + | |||
| + | def mul(num1, num2): | ||
| + | ''' | ||
| + | Miltiplies of two numbers and prints the result | ||
| + | :param num1: first number | ||
| + | :param num2: second number | ||
| + | :return: None | ||
| + | ''' | ||
| + | print(num1 * num2) | ||
| + | |||
| + | def main(): | ||
| + | add(5,5) | ||
| + | mul(5, 5) | ||
| + | print(addition(5, | ||
| + | print(multiplication(5, | ||
| + | |||
| + | if __name__ == ' | ||
| + | main() | ||
| + | |||
| + | </ | ||
| + | </ | ||
| + | |||
| + | Testen Sie die Implementierung mit '' | ||
| + | |||
| + | ==== Teilaufgabe 5 ==== | ||
| + | |||
| + | Importieren Sie das Modul '' | ||
| + | |||
| + | <WRAP center round box 60%> | ||
| + | <code python> | ||
| + | #Add import statement for calculator in math_operations package | ||
| + | |||
| + | def main(): | ||
| + | print(calculator.add(5, | ||
| + | print(calculator.mul(5, | ||
| + | |||
| + | if __name__ == ' | ||
| + | main() | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | Testen Sie die Implementierung mit '' | ||
| + | |||
| + | ==== Teilaufgabe 6 ==== | ||
| + | |||
| + | Importieren Sie '' | ||
| + | |||
| + | <WRAP center round box 60%> | ||
| + | <code python> | ||
| + | #Add import statement for add and mul from calculator in math_operations package | ||
| + | |||
| + | def main(): | ||
| + | print(add(5, | ||
| + | print(mul(5, | ||
| + | |||
| + | if __name__ == ' | ||
| + | main() | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | Testen Sie die Implementierung mit '' | ||
| + | |||
| + | ---- | ||
| + | < | ||
| + | < | ||
| + | GitHub Repository https:// | ||
| + | |||
| + | //Lernende am BZZ müssen den Link zum GitHub Classroom Assignment verwenden// | ||
| + | |||
| + | </ | ||
| + | {{tag> | ||
| + | [[https:// | ||