Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- def addieren(array):
- summe = 0
- for i in range(0,len(array)):
- summe += array[i]
- return summe
- def multiplikation(array):
- produkt = 1
- for i in range(0,len(array)):
- produkt *= array[i]
- return produkt
- def verdopplung(array):
- doppel = array.copy()
- for i in range(0,len(doppel)):
- doppel.append(array[i]*-1)
- return doppel
- def eingaben(eingabe_zahl):
- try:
- float(eingabe_zahl)
- array2.append(float(eingabe_zahl))
- except ValueError:
- if(eingabe_zahl == "s" or eingabe_zahl == "d" or eingabe_zahl == "m"):
- return eingabe_zahl
- else:
- print("Fehler! Deine Eingabe: ", eingabe_zahl ,"entspricht nicht den Anforderungen, die bisherigen Eingaben ", array2 , "bleiben bestehen.")
- print("Bitte nur Kommazahlen und zum Abschluss des Zeichen fuer den Modus eingeben. Die Modi sind: s fuer Summe, m fuer Multiplikation und d fuer Verdopplung!")
- return "E"
- return "N"
- array2 = []
- modus = "x"
- for i in range(1,len(sys.argv)):
- modus = eingaben(sys.argv[i])
- if(modus == "E"):
- break
- while(modus == "E" or modus == "N"):
- modus = eingaben(input("Bitte gib einen weitere Kommazahl oder einen Modus (s, m, d) ein: "))
- if(modus == "s"):
- print("Summe: ", addieren(array2))
- elif(modus == "d"):
- print("Verdopplung: ", verdopplung(array2))
- elif (modus == "m"):
- print("Produkt: ", multiplikation(array2))
- else:
- print("Wie hast du das denn hinbekommen?!?!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement