Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Autor: Julian Jäger
- Eckener-Gymnasium
- 8.4.2011
- Russische Bauernmultiplikation
- '''
- print("Bitte geben Sie zwei Zahlen ein, die sie miteinander multiplizieren möchten!")
- error=0
- while error == 0:
- a = 0
- while a == 0:
- try:
- Zahl1 = int(input("1. Zahl: "))
- Zahl2 = int(input("2. Zahl: "))
- a= 1337
- except:
- print("Sie müssen natürliche Zahlen eingeben!\n")
- if Zahl1 % 2 != 0:
- Result = Zahl2
- else:
- Result = 0
- while Zahl1 != 1:
- Zahl2 = Zahl2*2
- Zahl1 = Zahl1 // 2
- if Zahl1 % 2 != 0:
- Result = Result + Zahl2
- ####Ausgabe
- #print("")
- print("Russische Bauernmultiplikation ergibt (", Result, ") \n")
- print("---> Neue eingabe: ")
Advertisement
Add Comment
Please, Sign In to add comment