Path: ...!news.mixmin.net!proxad.net!feeder1-2.proxad.net!cleanfeed1-b.proxad.net!nnrp6-1.free.fr!not-for-mail From: Damien Wyart Newsgroups: fr.comp.lang.python Subject: Re: Autre exercice : calculer la somme de x chiffres. Organization: Serveur de News Free References: Date: Mon, 23 May 2022 09:36:54 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Lines: 22 Message-ID: <628b3996$0$26316$426a74cc@news.free.fr> NNTP-Posting-Date: 23 May 2022 09:36:54 CEST NNTP-Posting-Host: 92.170.39.26 X-Trace: 1653291414 news-1.free.fr 26316 92.170.39.26:42642 X-Complaints-To: abuse@proxad.net Bytes: 1419 * Dominique in fr.comp.lang.python: > Inutile de passer par une composition de liste : > def addition(x): > return sum(range(x+1)) > print (addition(int(input('Fin de la sommielle ')))) > Difficile sans doute d'être plus concis... Je trouve qu'imbriquer tous les appels n'est pas très lisible ; je proposerais plutôt : def sum_of_first_ints(n): return sum(range(n+1)) N = int(input("Please enter an integer: ")) print("The sum from 1 to", N, "is", sum_of_first_ints(N)) -- DW