Skip to content

Instantly share code, notes, and snippets.

@sthesing
Created May 17, 2017 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sthesing/ecd8789964c073c9859828439ec4f8d9 to your computer and use it in GitHub Desktop.
Save sthesing/ecd8789964c073c9859828439ec4f8d9 to your computer and use it in GitHub Desktop.
Rechner Beispiel aus dem KBQ-Kurs Programmieren für Anfänger
def plus(zahl1, zahl2):
""""
Addiert zwei Zahlen.
"""
ergebnis = int(zahl1) + int(zahl2)
return ergebnis
def minus(zahl1, zahl2):
""""
Substrahiert die zweite Zahl von der ersten Zahl.
"""
ergebnis = int(zahl1) - int(zahl2)
return ergebnis
def geteilt(zahl1, zahl2):
""""
Teilt die erste Zahl durch die zweite Zahl.
"""
ergebnis = int(zahl1) / int(zahl2)
return ergebnis
def mal(zahl1, zahl2):
""""
Multipliziert zwei Zahlen.
"""
ergebnis = int(zahl1) * int(zahl2)
return ergebnis
print(1, "Plusrechnen")
print(2, "Minusrechnen")
print(3, "Teilen")
print(4, "Malnehmen")
methode = input("Welche Rechenmethode wollen Sie? (1-4): ")
erstezahl = input("Geben Sie die erste Zahl ein: ")
zweitezahl = input("Geben Sie die zweite Zahl ein: ")
if methode == "1":
print("Es kommt eine Plus-Rechnung:")
rueckgabe = plus(erstezahl, zweitezahl)
if methode == "2":
print("Es kommt eine Minus-Rechnung:")
rueckgabe = minus(erstezahl, zweitezahl)
if methode == "3":
print("Es kommt eine Geteilt-Rechnung:")
rueckgabe = geteilt(erstezahl, zweitezahl)
if methode == "4":
print("Es kommt eine Mal-Rechnung:")
rueckgabe = mal(erstezahl, zweitezahl)
print("Das Ergebnis ist: ", rueckgabe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment