dimanche 28 avril 2019

Keeping original input in consideration for final product

I am attempting to take two inputs, a and b, and perform an operation. My code is as follows:

a = int(input("Enter an integer A to be multiplied: "))
b = int(input("Enter an integer B to be multiplied: "))
x = 0

while True:
    print(a, b)
    b //= 2
    a *= 2
    if b < 1:
        break
    if b % 2 == 1:
        new = [a]
        for i in new:
            x += i
print(x)

If I enter 34 and 19, the output is:

Enter an integer A to be multiplied: 34
Enter an integer B to be multiplied: 19
34 19
68 9
136 4
272 2
544 1
612

The answer should be 646, as the remainder of 19%2 is 1. Why does my code not consider 34, 19 while going through the second if statement?

Aucun commentaire:

Enregistrer un commentaire