sec_algo_boucles_cours1.py

Created by morelo-lolo

Created on February 20, 2022

361 Bytes

Exemples de boucles non bornées


from math import *

def exemple1():
  seuil =1000
  n=0
  while n**2<seuil :
    n=n+1
    print(n,n**2)
  return n,n**2
  
def exemple2():
  p=1
  n=0
  while p<1000000:
    p=p*2
    n=n+1
    print(n,p)
  return n , p

def exemple3(seuil) :
  Somme=0
  n=0
  while Somme<seuil:
    Somme=Somme+n
    n=n+1
  return n-1,Somme


During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.