StoryMakerTV

[PYTHON 3] Russische Bauernmultiplikation

Apr 9th, 2011
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. '''
  2. Autor: Julian Jäger
  3. Eckener-Gymnasium
  4.  
  5. 8.4.2011
  6. Russische Bauernmultiplikation
  7.  
  8. '''
  9.  
  10. print("Bitte geben Sie zwei Zahlen ein, die sie miteinander multiplizieren möchten!")
  11. error=0
  12.  
  13. while error == 0:
  14.  
  15.     a = 0
  16.     while a == 0:
  17.         try:
  18.             Zahl1 = int(input("1. Zahl: "))
  19.             Zahl2 = int(input("2. Zahl: "))
  20.             a= 1337
  21.         except:
  22.             print("Sie müssen natürliche Zahlen eingeben!\n")
  23.            
  24.  
  25.     if Zahl1 % 2 != 0:
  26.         Result = Zahl2
  27.     else:
  28.         Result = 0
  29.  
  30.     while Zahl1 != 1:
  31.         Zahl2 = Zahl2*2
  32.         Zahl1 = Zahl1 // 2
  33.         if Zahl1 % 2 != 0:
  34.             Result = Result + Zahl2
  35.  
  36.  
  37.  
  38.     ####Ausgabe
  39.     #print("")
  40.     print("Russische Bauernmultiplikation ergibt (", Result, ") \n")
  41.  
  42.     print("---> Neue eingabe: ")
Advertisement
Add Comment
Please, Sign In to add comment