Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #60180
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <gary.herron@islandtraining.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'odd': 0.07; 'follows.': 0.09; 'function,': 0.09; 'received:67.192': 0.09; 'received:67.192.241': 0.09; 'received:dfw.emailsrvr.com': 0.09; 'subject:Help': 0.11; 'def': 0.12; 'correct)': 0.16; 'iteration': 0.16; 'skip:[ 40': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'result.': 0.19; 'input': 0.22; 'otherwise,': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'integer': 0.24; 'received:emailsrvr.com': 0.24; "haven't": 0.24; 'looks': 0.24; 'question': 0.24; 'received:(smtp server)': 0.26; 'suggested': 0.26; 'second': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'correct': 0.29; 'gary': 0.31; 'run': 0.32; '"the': 0.34; "can't": 0.35; 'problem.': 0.35; 'but': 0.35; 'add': 0.35; 'sequence': 0.36; 'should': 0.36; 'example,': 0.37; 'positive': 0.37; 'list': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'does': 0.39; 'itself': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'even': 0.60; 'tell': 0.60; 'back': 0.62; 'email addr:gmail.com': 0.63; 'refer': 0.63; 'repeat': 0.74; '(apparently': 0.84; 'algorithm,': 0.84; 'subject:Friend': 0.91 |
| X-Virus-Scanned | OK |
| Date | Thu, 21 Nov 2013 15:35:41 -0800 |
| From | Gary Herron <gary.herron@islandtraining.com> |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Newbie - Trying to Help a Friend |
| References | <0e127888-4bfa-4f14-aa55-df8ef53284a3@googlegroups.com> <528c31e9$0$11089$c3e8da3@news.astraweb.com> <mailman.2952.1384926851.18130.python-list@python.org> <ci%iu.79106$v_6.55095@fx20.am4> <mailman.2959.1384955870.18130.python-list@python.org> <r_3ju.169172$v41.72763@fx23.am4> <8e4ju.71474$Xe4.3764@fx34.am4> <Xg4ju.71519$Xe4.11829@fx34.am4> <mailman.2968.1384960462.18130.python-list@python.org> <WD4ju.169174$v41.154149@fx23.am4> <mailman.2975.1384965010.18130.python-list@python.org> <c207052d-22d9-40db-989d-85a80b4b981a@googlegroups.com> <mailman.2979.1384969067.18130.python-list@python.org> <15a6e59c-1ebc-44dc-9441-b2410a49ab98@googlegroups.com> <l6itsv$q1a$1@ger.gmane.org> <528DF430.1060608@rece.vub.ac.be> <CAPTjJmpE1qogG59KqMvO_kO3fxRxPc5EvvyazLEeFTZm4smqEQ@mail.gmail.com> <CAHWX4tH-uFV3YXGPFPX9hRihHT2+WFOXM-gan4zp3aFCzMQqXg@mail.gmail.com> <mailman.3012.1385053851.18130.python-list@python.org> <29330860-484d-4cc8-b01c-0460fb55c251@googlegroups.com> |
| In-Reply-To | <29330860-484d-4cc8-b01c-0460fb55c251@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3018.1385077304.18130.python-list@python.org> (permalink) |
| Lines | 38 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1385077304 news.xs4all.nl 15915 [2001:888:2000:d::a6]:37247 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:60180 |
Show key headers only | View raw
On 11/21/2013 03:17 PM, bradleybooth12345@gmail.com wrote: > Coming back to the second question > > "The collatz process is as follows. Take a positive integer n greater than 1. while n is greater than 1 repeat the following; if N is even halve it and if N is odd multiply it by 3 and add 1. The (Unsolved) collatz conjecture is that this process always terminates. > > The user should be prompted to supply the number n, and your program should build the list of values taken by sucessive iteration of the algorithm, and print it out. For example, if 7 is input your program should print the list > > [7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1] > > We've managed to come up with this, but obviously it's wrong. Any Idea's? > > def collatz_sequence (n) : > seq = [ ] > if n < 1 : > return [ ] > while n > 1: > if n % 2 == 0: > n = n/2 > else: > n = 3*n+ 1 > seq.append (n) > return seq Why do you say it's wrong? What does it do? What was expected? I see that your indentations don't match, but I can't tell if that's your error or an email problem. Is that the 'obviously wrong' part? I also see that you create an (apparently correct) function, which returns a nice result. But you haven't called the function to actually run it with a specific value to be printed out. Perhaps that's the 'obviously wrong' part you refer to. However, the function itself looks correct otherwise, although you may want to start the sequence off with [n] rather than [] so as to match the suggested output. Gary Herron
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Newbie - Trying to Help a Friend bradleybooth12345@gmail.com - 2013-11-19 10:40 -0800
Re: Newbie - Trying to Help a Friend maxwell34m@gmail.com - 2013-11-19 11:05 -0800
Re: Newbie - Trying to Help a Friend Neil Cerutti <mr.cerutti@gmail.com> - 2013-11-19 14:07 -0500
Re: Newbie - Trying to Help a Friend Gary Herron <gary.herron@islandtraining.com> - 2013-11-19 11:06 -0800
Re: Newbie - Trying to Help a Friend bradleybooth12345@gmail.com - 2013-11-19 11:27 -0800
Re: Newbie - Trying to Help a Friend Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-19 20:48 +0000
Re: Newbie - Trying to Help a Friend Duncan Booth <duncan.booth@invalid.invalid> - 2013-11-20 11:38 +0000
Re: Newbie - Trying to Help a Friend Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-23 02:03 +0000
Re: Newbie - Trying to Help a Friend Mark Janssen <dreamingforward@gmail.com> - 2013-11-19 14:51 -0800
Re: Newbie - Trying to Help a Friend Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-20 00:17 +0000
Re: Newbie - Trying to Help a Friend Dave Angel <davea@davea.name> - 2013-11-19 22:10 -0500
Re: Newbie - Trying to Help a Friend Steven D'Aprano <steve@pearwood.info> - 2013-11-20 03:52 +0000
Re: Newbie - Trying to Help a Friend Dave Angel <davea@davea.name> - 2013-11-20 00:54 -0500
Re: Newbie - Trying to Help a Friend Alister <alister.ware@ntlworld.com> - 2013-11-20 09:29 +0000
Re: Newbie - Trying to Help a Friend Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-20 13:57 +0000
Re: Newbie - Trying to Help a Friend Alister <alister.ware@ntlworld.com> - 2013-11-20 14:51 +0000
Re: Newbie - Trying to Help a Friend Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-11-20 18:33 -0500
Re: Newbie - Trying to Help a Friend Anssi Saari <as@sci.fi> - 2013-11-21 15:44 +0200
Re: Newbie - Trying to Help a Friend Alister <alister.ware@ntlworld.com> - 2013-11-20 14:49 +0000
Re: Newbie - Trying to Help a Friend Chris Angelico <rosuav@gmail.com> - 2013-11-21 02:05 +1100
Re: Newbie - Trying to Help a Friend Alister <alister.ware@ntlworld.com> - 2013-11-20 15:06 +0000
Re: Newbie - Trying to Help a Friend Alister <alister.ware@ntlworld.com> - 2013-11-20 15:09 +0000
Re: Newbie - Trying to Help a Friend Chris Angelico <rosuav@gmail.com> - 2013-11-21 02:14 +1100
Re: Newbie - Trying to Help a Friend Alister <alister.ware@ntlworld.com> - 2013-11-20 15:35 +0000
Multiple postings Alister <alister.ware@ntlworld.com> - 2013-11-20 15:36 +0000
Re: Newbie - Trying to Help a Friend Alister <alister.ware@ntlworld.com> - 2013-11-20 15:34 +0000
Re: Newbie - Trying to Help a Friend Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-20 16:29 +0000
Re: Newbie - Trying to Help a Friend Alister <alister.ware@ntlworld.com> - 2013-11-20 16:45 +0000
Re: Newbie - Trying to Help a Friend Ned Batchelder <ned@nedbatchelder.com> - 2013-11-20 09:12 -0800
Re: Newbie - Trying to Help a Friend Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-20 17:37 +0000
Re: Newbie - Trying to Help a Friend Ned Batchelder <ned@nedbatchelder.com> - 2013-11-20 09:51 -0800
Re: Newbie - Trying to Help a Friend Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-20 18:09 +0000
Re: Newbie - Trying to Help a Friend Ned Batchelder <ned@nedbatchelder.com> - 2013-11-20 10:18 -0800
Re: Newbie - Trying to Help a Friend Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-20 18:35 +0000
Re: Newbie - Trying to Help a Friend Ned Batchelder <ned@nedbatchelder.com> - 2013-11-20 11:54 -0800
Re: Newbie - Trying to Help a Friend Chris Angelico <rosuav@gmail.com> - 2013-11-21 07:26 +1100
Off-topic: Pop culture references [was Re: Newbie - Trying to Help a Friend] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-21 00:27 +0000
Re: Off-topic: Pop culture references [was Re: Newbie - Trying to Help a Friend] MRAB <python@mrabarnett.plus.com> - 2013-11-21 00:48 +0000
Re: Off-topic: Pop culture references [was Re: Newbie - Trying to Help a Friend] Tim Golden <mail@timgolden.me.uk> - 2013-11-21 09:08 +0000
Re: Off-topic: Pop culture references [was Re: Newbie - Trying to Help a Friend] Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-11-22 17:10 +1300
Re: Off-topic: Pop culture references [was Re: Newbie - Trying to Help a Friend] Chris Angelico <rosuav@gmail.com> - 2013-11-21 20:46 +1100
Re: Newbie - Trying to Help a Friend Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-11-21 12:53 +0100
Re: Newbie - Trying to Help a Friend Chris Angelico <rosuav@gmail.com> - 2013-11-22 02:48 +1100
Re: Newbie - Trying to Help a Friend Neil Cerutti <mr.cerutti@gmail.com> - 2013-11-21 11:29 -0500
Re: Newbie - Trying to Help a Friend Chris Angelico <rosuav@gmail.com> - 2013-11-22 04:10 +1100
Re: Newbie - Trying to Help a Friend bradleybooth12345@gmail.com - 2013-11-21 15:17 -0800
Re: Newbie - Trying to Help a Friend Gary Herron <gary.herron@islandtraining.com> - 2013-11-21 15:35 -0800
Re: Newbie - Trying to Help a Friend bradleybooth12345@gmail.com - 2013-11-21 15:55 -0800
Re: Newbie - Trying to Help a Friend Terry Reedy <tjreedy@udel.edu> - 2013-11-21 19:55 -0500
Re: Newbie - Trying to Help a Friend Gary Herron <gary.herron@islandtraining.com> - 2013-11-21 20:17 -0800
Re: Newbie - Trying to Help a Friend Terry Reedy <tjreedy@udel.edu> - 2013-11-21 19:17 -0500
Re: Newbie - Trying to Help a Friend Alister <alister.ware@ntlworld.com> - 2013-11-20 15:34 +0000
Re: Newbie - Trying to Help a Friend Alister <alister.ware@ntlworld.com> - 2013-11-20 15:06 +0000
Re: Newbie - Trying to Help a Friend Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-20 15:24 +0000
Re: Newbie - Trying to Help a Friend Alister <alister.ware@ntlworld.com> - 2013-11-20 14:50 +0000
Re: Newbie - Trying to Help a Friend Alister <alister.ware@ntlworld.com> - 2013-11-20 14:50 +0000
Re: Newbie - Trying to Help a Friend Alister <alister.ware@ntlworld.com> - 2013-11-20 09:29 +0000
csiph-web