python: new examples

parent d1784bcc
print("racine carrée entière")
n = int(input("entrez n : "))
#@ assume n >= 0
r = 0
s = 1
while s <= n:
#@ invariant 0 <= r
#@ invariant r * r <= n
#@ invariant s == (r+1) * (r+1)
r = r + 1
s = s + 2 * r + 1
print(r)
#@ assert r*r <= n < (r+1)*(r+1)
print("somme des n premiers entiers")
n = int(input("entrez n : "))
#@ assume n >= 0
s = 0
k = 0
while k <= n:
#@ invariant 0 <= k <= n+1
#@ invariant 2 * s == (k - 1) * k
s = s + k
k = k + 1
print(s)
#@ assert 2 * s == n * (n+1)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment