I'm having a problem with my program and I'm not sure how to correct it
(I'm in an intro programming class).

My program is supposed two numbers and count the number of carry
operations.

This is what I have:

n1 = int(raw_input('Number #1: '))
n2 = int(raw_input('Number #2: '))
add = n1 + n2
print ' '
print n1, '+', n2, '=', add
print ' '
sn1 = str(n1)
sn2 = str(n2)
num1 = 1
num2 = 1
num1 == num2
last_n1 = sn1[-num1]
last_n2 = sn2[-num2]
int_lastn1 = int(last_n1)
int_lastn2 = int(last_n2)
eq = int_lastn1 + int_lastn2
carry = 0
while eq >= 10 and carry < len(sn1) and carry < len(sn2):
    num1 += 1
    num2 += 1
    carry += 1
print 'Number of carries:', carry

When I input 239 & 123 as my two numbers it equals 362, which is correct.
But it says I have 3 carries, when the answer should be 1 carry operation.

I'm not sure how to correct this error.

Thanks,

Taylor
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to