Help please

khaosyt at gmail.com khaosyt at gmail.com
Mon Apr 1 01:15:54 EDT 2013


I want to add up the integers of this code in one line. For example, if I had the code

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): ")

and inputted "54321," it would look like:
Enter a positive integer: 54321
5
4
3
2
1
Again? (Y/N): n

What I want to do is add up the "54321" so it comes out with
"Sum of digits is 15." on one line.

Thanks!



More information about the Python-list mailing list