Files
why3/examples/python/mult.py
paulpatault 3671864507 Python: Added examples
- New examples using the new syntax (+=, ...)
- New examples using the new methods (.pop(), .append(), ...)
- Update old examples with assignement operators (+=, ...)
2021-06-24 11:44:07 +02:00

29 lines
395 B
Python

print("la multiplication dite russe")
a = int(input("entrez a : "))
b = int(input("entrez b : "))
p = a
q = b
if q < 0:
p = -a
q = -b
#@ assert q >= 0
r = 0
while q > 0:
#@ invariant 0 <= q
#@ invariant r + p * q == a * b
#@ variant q
print(p, q, r)
if q % 2 == 1:
r += p
p += p
q //= 2
print(p, q, r)
print("a * b =", r)
#@ assert r == a * b