{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "_Aufgabe 1_\n", "\n", "Schreiben Sie ein Python-Programm, das drei Zahlen von der Tastatur einliest und anschließend die\n", "größte von ihnen ausgibt." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "pycharm": { "is_executing": false, "name": "#%%\n" }, "slideshow": { "slide_type": "slide" } }, "outputs": [], "source": [ "num1 = float(input(\"Erste Zahl:\"))\n", "num2 = float(input(\"Zweite Zahl:\"))\n", "num3 = float(input(\"Dritte Zahl:\"))\n", "\n", "maximum = num1 if num1 > num2 else num2\n", "maximum = maximum if maximum > num3 else num3\n", "print(maximum) \n", "\n", "\n", "if num1 > num2:\n", " if num1 > num3:\n", " print(num1)\n", " else:\n", " print(num3)\n", "else:\n", " if num2 > num3:\n", " print(num2)\n", " else:\n", " print(num3)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "_Aufgabe 2_\n", "\n", "Schreiben Sie ein Python-Programm, das zwei Zahlen von der Tastatur einliest. Anschließend soll\n", "nachgefragt werden, ob die beiden Zahlen addiert, subtrahiert, mulitpliziert oder dividiert werden sollen. \n", "Führen Sie die gewünschte Operation aus und geben Sie das Ergebnis aus. " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "pycharm": { "name": "#%%\n" }, "slideshow": { "slide_type": "slide" } }, "outputs": [], "source": [ "num1 = float(input(\"Erste Zahl:\"))\n", "num2 = float(input(\"Zweite Zahl:\"))\n", "\n", "op = input(\"Was soll gemacht werden (+,-,*,/):\")\n", "if op == \"+\":\n", " erg = num1 + num2\n", "elif op == \"-\":\n", " erg = num1 - num2\n", "elif op == \"*\":\n", " erg = num1 * num2\n", "elif op == \"/\":\n", " erg = num1 / num2\n", "else:\n", " erg = None\n", " \n", "print(f\"Unbekannter Operator <{op}>.\") if erg is None else print(f\"{num1} {op} {num2} = {erg}\")" ] } ], "metadata": { "celltoolbar": "Slideshow", "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.9" }, "pycharm": { "stem_cell": { "cell_type": "raw", "metadata": { "collapsed": false }, "source": [] } } }, "nbformat": 4, "nbformat_minor": 1 }