Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. import sys
  2.  
  3. def addieren(array):
  4.     summe = 0
  5.     for i in range(0,len(array)):
  6.         summe += array[i]
  7.     return summe
  8.  
  9. def multiplikation(array):
  10.     produkt = 1
  11.     for i in range(0,len(array)):
  12.         produkt *= array[i]
  13.     return produkt
  14.  
  15. def verdopplung(array):
  16.     doppel = array.copy()
  17.     for i in range(0,len(doppel)):
  18.         doppel.append(array[i]*-1)
  19.     return doppel
  20.  
  21.  
  22. def eingaben(eingabe_zahl):
  23.     try:
  24.         float(eingabe_zahl)
  25.         array2.append(float(eingabe_zahl))
  26.     except ValueError:
  27.         if(eingabe_zahl == "s" or eingabe_zahl == "d" or eingabe_zahl == "m"):
  28.             return eingabe_zahl
  29.         else:
  30.             print("Fehler! Deine Eingabe: ", eingabe_zahl ,"entspricht nicht den Anforderungen, die bisherigen Eingaben ", array2 , "bleiben bestehen.")
  31.             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!")
  32.  
  33.             return "E"
  34.     return "N"
  35.  
  36. array2 = []
  37.  
  38. modus = "x"
  39.  
  40. for i in range(1,len(sys.argv)):
  41.     modus = eingaben(sys.argv[i])
  42.     if(modus == "E"):
  43.         break
  44.  
  45. while(modus == "E" or modus == "N"):
  46.     modus = eingaben(input("Bitte gib einen weitere Kommazahl oder einen Modus (s, m, d) ein: "))
  47.  
  48. if(modus == "s"):
  49.     print("Summe: ", addieren(array2))
  50. elif(modus == "d"):
  51.     print("Verdopplung: ", verdopplung(array2))
  52. elif (modus == "m"):
  53.     print("Produkt: ", multiplikation(array2))
  54. else:
  55.     print("Wie hast du das denn hinbekommen?!?!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement