Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > fr.comp.lang.python > #3496

Re: Somme, récursive

From Benoit Izac <use.reply.to@INVALID.ADDRESS>
Newsgroups fr.comp.lang.python
Subject Re: Somme, récursive
Date 2021-04-30 21:15 +0200
Message-ID <878s4za8ij.fsf@izac.org> (permalink)
References (1 earlier) <87mttgakrp.fsf@izac.org> <s6h6e3$k80$1@cabale.usenet-fr.net> <s6h72u$mo6$1@cabale.usenet-fr.net> <87im43abkm.fsf@izac.org> <bPmdnVxpYv1byRH9nZ2dnUU7983NnZ2d@giganews.com>

Show all headers | View raw


Bonjour,

Le 30/04/2021 à 21:04, raph a écrit dans le message
<bPmdnVxpYv1byRH9nZ2dnUU7983NnZ2d@giganews.com> :

> J'ai finis par réussir, voici le code pour ceux qu'ils le veulent :)
> Et merci encore pour votre aide.
> T = [4,7,5,5,2,6,9,3,8,4]
> def somme(liste,result=0):
>      if len(liste)<=0:
>           return result
>      else:
>           result+=liste[0]
>           del liste[0]
>           return somme(liste, result)

Mouais…

>>> T = [4,7,5,5,2,6,9,3,8,4]
>>> def somme(liste,result=0):
...      if len(liste)<=0:
...           return result
...      else:
...           result+=liste[0]
...           del liste[0]
...           return somme(liste, result)
...
>>> somme(T)
53
>>> T
[]

Oups !

-- 
Benoit Izac

Back to fr.comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Somme, récursive raph14 <nospam_rgb.baralle@gmail.com.invalid> - 2021-04-29 14:38 -0500
  Re: Somme, récursive Benoit Izac <use.reply.to@INVALID.ADDRESS> - 2021-04-29 22:38 +0200
    Re: Somme, récursive Dominique <zzz@aol.com.invalid> - 2021-04-30 07:02 +0200
      Re: Somme, récursive Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2021-04-30 12:07 +0200
    Re: Somme, récursive raph14 <nospam_rgb.baralle@gmail.com.invalid> - 2021-04-30 09:56 -0500
    Re: Somme, récursive raph14 <nospam_rgb.baralle@gmail.com.invalid> - 2021-04-30 09:57 -0500
    Re: Somme, récursive Olivier Miakinen <om+news@miakinen.net> - 2021-04-30 17:06 +0200
      Re: Somme, récursive Olivier Miakinen <om+news@miakinen.net> - 2021-04-30 17:17 +0200
        Re: Somme, récursive Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2021-04-30 18:14 +0200
          Re: Somme, récursive raph14 <nospam_rgb.baralle@gmail.com.invalid> - 2021-04-30 11:46 -0500
        Re: Somme, récursive Benoit Izac <use.reply.to@INVALID.ADDRESS> - 2021-04-30 20:09 +0200
          Re: Somme, récursive raph14 <nospam_rgb.baralle@gmail.com.invalid> - 2021-04-30 14:04 -0500
            Re: Somme, récursive Benoit Izac <use.reply.to@INVALID.ADDRESS> - 2021-04-30 21:15 +0200
  Re: Somme, récursive debimax <debimax@free.fr> - 2021-04-30 15:03 +0200
    Re: Somme, récursive Dominique <zzz@aol.com.invalid> - 2021-04-30 18:46 +0200
      Re: Somme, récursive debimax <debimax@free.fr> - 2021-04-30 22:05 +0200
        Re: Somme, récursive Dominique <zzz@aol.com.invalid> - 2021-05-01 04:39 +0200

csiph-web