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


Groups > comp.lang.python > #42134

Re: Help printing the integers of a longer number

References <7764e61c-e4cc-413a-a76d-2d37f39abc61@googlegroups.com>
Date 2013-03-29 01:48 +1100
Subject Re: Help printing the integers of a longer number
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3877.1364482107.2939.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, Mar 29, 2013 at 1:39 AM,  <khaosyt@gmail.com> wrote:
> I want to print the individual numbers of a large number using division and modulus division.
>
> For example:
>
> Enter a positive integer: 54321
> 5
> 4
> 3
> 2
> 1

Python has two operators that can help here:

// for integer division - returns the quotient without the remainder
% for modulus - returns the remainder

You'll also want to use a while loop to continue gathering digits so
long as there's something left in the number.

And if you want the digits to come out in that order, you're probably
going to want to gather them into a list and then output them in
reverse. But start by ignoring that part and producing something that,
for the input 54321, produces 1, 2, 3, 4, and then 5.

Finally, when you're asking about homework, please be honest about it.
We can tell, you're not putting one over us :) Better still, post your
non-working code and explain where you're having trouble; we'll be
happy to help you learn, but we won't simply give you the answer.

ChrisA

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


Thread

Help printing the integers of a longer number khaosyt@gmail.com - 2013-03-28 07:39 -0700
  Re: Help printing the integers of a longer number Chris Angelico <rosuav@gmail.com> - 2013-03-29 01:48 +1100
  Re: Help printing the integers of a longer number Joel Goldstick <joel.goldstick@gmail.com> - 2013-03-28 10:48 -0400
  Re: Help printing the integers of a longer number Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-03-28 19:03 +0200
    Re: Help printing the integers of a longer number Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-03-28 19:11 +0200
      Re: Help printing the integers of a longer number Chris Angelico <rosuav@gmail.com> - 2013-03-29 04:19 +1100
    Re: Help printing the integers of a longer number Chris Angelico <rosuav@gmail.com> - 2013-03-29 04:17 +1100

csiph-web