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


Groups > comp.lang.python > #42502 > unrolled thread

Help

Started bykhaosyt@gmail.com
First post2013-04-01 14:02 -0700
Last post2013-04-01 16:55 -0700
Articles 14 — 6 participants

Back to article view | Back to comp.lang.python


Contents

  Help khaosyt@gmail.com - 2013-04-01 14:02 -0700
    Re: Help khaosyt@gmail.com - 2013-04-01 14:42 -0700
      Re: Help Dave Angel <davea@davea.name> - 2013-04-01 18:28 -0400
    Re: Help khaosyt@gmail.com - 2013-04-01 14:42 -0700
      Re: Help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-04-01 23:09 +0100
        Re: Help khaosyt@gmail.com - 2013-04-01 15:12 -0700
          Re: Help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-04-01 23:29 +0100
        Re: Help khaosyt@gmail.com - 2013-04-01 15:12 -0700
          Re: Help Walter Hurry <walterhurry@lavabit.com> - 2013-04-01 23:56 +0000
            Re: Help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-04-02 02:02 +0100
              Re: Help Walter Hurry <walterhurry@lavabit.com> - 2013-04-02 23:41 +0000
        Re: Help Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-01 23:42 +0000
          Re: Help Roy Smith <roy@panix.com> - 2013-04-01 19:47 -0400
            Re: Help khaosyt@gmail.com - 2013-04-01 16:55 -0700

#42502 — Help

Fromkhaosyt@gmail.com
Date2013-04-01 14:02 -0700
SubjectHelp
Message-ID<d7343665-0b72-4424-89b0-89c5343acb82@googlegroups.com>
If I wanted to get the sum of some numbers (for example: 1 + 2 + 3 + 4 + 5 = 15) from the attached program what do I do? Keep in mind that the print statement prints the integers individually.

integer = 0
denom = 10
again = "y" #sentinel:
while again == "y" or again == "Y":
    integer = input("Enter a positive integer: ")
    while denom <= integer:
        denom = denom*10
    while denom > 1:
        denom = denom/10
        number = integer/denom
        integer = integer%denom
        print str(number)
    again = raw_input("Again? (Y/N): ")

[toc] | [next] | [standalone]


#42506

Fromkhaosyt@gmail.com
Date2013-04-01 14:42 -0700
Message-ID<8fb27db9-e745-449e-b7f6-e30493f05b35@googlegroups.com>
In reply to#42502
Self-bump

[toc] | [prev] | [next] | [standalone]


#42515

FromDave Angel <davea@davea.name>
Date2013-04-01 18:28 -0400
Message-ID<mailman.22.1364855320.17481.python-list@python.org>
In reply to#42506
On 04/01/2013 05:42 PM, khaosyt@gmail.com wrote:
> Self-bump
>

Normally, bumping a message/thread means replying to it.  You're leaving 
a NEW message with no context, no reply, and a different uninformative 
subject line.  And you're leaving it from googlegroups, with two copies.

If you want to sum things through a loop, initialize a variable to zero 
before the loop, then add to it each time through the loop.

total=0
for  whatever in something:
     total += whatever_expression

print total


-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#42507

Fromkhaosyt@gmail.com
Date2013-04-01 14:42 -0700
Message-ID<bba78541-ce2f-4f12-a4dc-aef352386ddf@googlegroups.com>
In reply to#42502
Self-bump

[toc] | [prev] | [next] | [standalone]


#42510

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-04-01 23:09 +0100
Message-ID<mailman.20.1364854047.17481.python-list@python.org>
In reply to#42507
On 01/04/2013 22:42, khaosyt@gmail.com wrote:
> Self-bump
>

It's considered polite to wait for at least 24 hours before bumping a 
question.  You might have got more answers if you'd given a decent 
subject line rather than "Help".

As it happens all you need do is loop around the string that is input, 
converting every digit to an integer and storing them in a list, then 
call the builtin sum function against the stored list.

You'll probably also need a try/except to handle any duff input.

-- 
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#42511

Fromkhaosyt@gmail.com
Date2013-04-01 15:12 -0700
Message-ID<758c0049-1bde-46de-a331-be3343618599@googlegroups.com>
In reply to#42510
On Monday, April 1, 2013 6:09:04 PM UTC-4, Mark Lawrence wrote:
> On 01/04/2013 22:42, khaosyt@gmail.com wrote:
> 
> > Self-bump
> 
> >
> 
> 
> 
> It's considered polite to wait for at least 24 hours before bumping a 
> 
> question.  You might have got more answers if you'd given a decent 
> 
> subject line rather than "Help".
> 
> 
> 
> As it happens all you need do is loop around the string that is input, 
> 
> converting every digit to an integer and storing them in a list, then 
> 
> call the builtin sum function against the stored list.
> 
> 
> 
> You'll probably also need a try/except to handle any duff input.
> 
> 
> 
> -- 
> 
> If you're using GoogleCrap™ please read this 
> 
> http://wiki.python.org/moin/GoogleGroupsPython.
> 
> 
> 
> Mark Lawrence

How do I go about storing them in a list?

[toc] | [prev] | [next] | [standalone]


#42516

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-04-01 23:29 +0100
Message-ID<mailman.23.1364855329.17481.python-list@python.org>
In reply to#42511
On 01/04/2013 23:12, khaosyt@gmail.com wrote:
> On Monday, April 1, 2013 6:09:04 PM UTC-4, Mark Lawrence wrote:
>> On 01/04/2013 22:42, khaosyt@gmail.com wrote:
>>
>>> Self-bump
>>
>>>
>>
>>
>>
>> It's considered polite to wait for at least 24 hours before bumping a
>>
>> question.  You might have got more answers if you'd given a decent
>>
>> subject line rather than "Help".
>>
>>
>>
>> As it happens all you need do is loop around the string that is input,
>>
>> converting every digit to an integer and storing them in a list, then
>>
>> call the builtin sum function against the stored list.
>>
>>
>>
>> You'll probably also need a try/except to handle any duff input.
>>
>>
>>
>> --
>>
>> If you're using GoogleCrap™ please read this
>>
>> http://wiki.python.org/moin/GoogleGroupsPython.
>>
>>
>>
>> Mark Lawrence
>
> How do I go about storing them in a list?
>

Read this http://docs.python.org/3/tutorial/introduction.html#lists

-- 
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#42512

Fromkhaosyt@gmail.com
Date2013-04-01 15:12 -0700
Message-ID<mailman.21.1364854348.17481.python-list@python.org>
In reply to#42510
On Monday, April 1, 2013 6:09:04 PM UTC-4, Mark Lawrence wrote:
> On 01/04/2013 22:42, khaosyt@gmail.com wrote:
> 
> > Self-bump
> 
> >
> 
> 
> 
> It's considered polite to wait for at least 24 hours before bumping a 
> 
> question.  You might have got more answers if you'd given a decent 
> 
> subject line rather than "Help".
> 
> 
> 
> As it happens all you need do is loop around the string that is input, 
> 
> converting every digit to an integer and storing them in a list, then 
> 
> call the builtin sum function against the stored list.
> 
> 
> 
> You'll probably also need a try/except to handle any duff input.
> 
> 
> 
> -- 
> 
> If you're using GoogleCrap™ please read this 
> 
> http://wiki.python.org/moin/GoogleGroupsPython.
> 
> 
> 
> Mark Lawrence

How do I go about storing them in a list?

[toc] | [prev] | [next] | [standalone]


#42528

FromWalter Hurry <walterhurry@lavabit.com>
Date2013-04-01 23:56 +0000
Message-ID<kjd6r4$1q7$1@news.albasani.net>
In reply to#42512
On Mon, 01 Apr 2013 15:12:20 -0700, khaosyt wrote:

<snip triple spaced homework rubbish double posted>

Sigh. Another one for the bozo bin.

[toc] | [prev] | [next] | [standalone]


#42537

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-04-02 02:02 +0100
Message-ID<mailman.28.1364864541.17481.python-list@python.org>
In reply to#42528
On 02/04/2013 00:56, Walter Hurry wrote:
> On Mon, 01 Apr 2013 15:12:20 -0700, khaosyt wrote:
>
> <snip triple spaced homework rubbish double posted>
>
> Sigh. Another one for the bozo bin.
>

I say old chap you're setting yourself up for attacks from the Python 
Mailing List Police for using the word bozo, so expect a visit from 
Vicar Sergeant or Detective Parsons.  Oh sorry they're from the Church 
Police, but please be cautious anyway.

-- 
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#42615

FromWalter Hurry <walterhurry@lavabit.com>
Date2013-04-02 23:41 +0000
Message-ID<kjfqai$4b7$1@news.albasani.net>
In reply to#42537
On Tue, 02 Apr 2013 02:02:58 +0100, Mark Lawrence wrote:

> On 02/04/2013 00:56, Walter Hurry wrote:
>> On Mon, 01 Apr 2013 15:12:20 -0700, khaosyt wrote:
>>
>> <snip triple spaced homework rubbish double posted>
>>
>> Sigh. Another one for the bozo bin.
>>
>>
> I say old chap you're setting yourself up for attacks from the Python
> Mailing List Police for using the word bozo, so expect a visit from
> Vicar Sergeant or Detective Parsons.  Oh sorry they're from the Church
> Police, but please be cautious anyway.

Righty ho, old boy. I'll be more careful in future. Thanks! ;-)

[toc] | [prev] | [next] | [standalone]


#42522

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-04-01 23:42 +0000
Message-ID<515a1b7c$0$29967$c3e8da3$5496439d@news.astraweb.com>
In reply to#42510
On Mon, 01 Apr 2013 23:09:04 +0100, Mark Lawrence wrote:

> On 01/04/2013 22:42, khaosyt@gmail.com wrote:
>> Self-bump
>>
>>
> It's considered polite to wait for at least 24 hours before bumping a
> question.

Yes, but the assignment is due in an hour. Therefore it's critical that 
we reply instantly.

*wink*


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#42524

FromRoy Smith <roy@panix.com>
Date2013-04-01 19:47 -0400
Message-ID<roy-3ECF27.19475101042013@news.panix.com>
In reply to#42522
In article <515a1b7c$0$29967$c3e8da3$5496439d@news.astraweb.com>,
 Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:

> On Mon, 01 Apr 2013 23:09:04 +0100, Mark Lawrence wrote:
> 
> > On 01/04/2013 22:42, khaosyt@gmail.com wrote:
> >> Self-bump
> >>
> >>
> > It's considered polite to wait for at least 24 hours before bumping a
> > question.
> 
> Yes, but the assignment is due in an hour. Therefore it's critical that 
> we reply instantly.

How do you know it's an assignment?  It could be an interview.

[toc] | [prev] | [next] | [standalone]


#42527

Fromkhaosyt@gmail.com
Date2013-04-01 16:55 -0700
Message-ID<385dbcf0-bc21-4797-82fb-66ae03e5990a@googlegroups.com>
In reply to#42524
On Monday, April 1, 2013 7:47:51 PM UTC-4, Roy Smith wrote:
> In article <515a1b7c$0$29967$c3e8da3$5496439d@news.astraweb.com>,
> 
>  Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:
> 
> 
> 
> > On Mon, 01 Apr 2013 23:09:04 +0100, Mark Lawrence wrote:
> 
> > 
> 
> > > On 01/04/2013 22:42, khaosyt@gmail.com wrote:
> 
> > >> Self-bump
> 
> > >>
> 
> > >>
> 
> > > It's considered polite to wait for at least 24 hours before bumping a
> 
> > > question.
> 
> > 
> 
> > Yes, but the assignment is due in an hour. Therefore it's critical that 
> 
> > we reply instantly.
> 
> 
> 
> How do you know it's an assignment?  It could be an interview.

It's an assignment.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web