Home > Net >  multiplication of numbers from while loop
multiplication of numbers from while loop

Time:11-25

I am trying to multiply numbers that I get from the while loop. like 1.1 * 1.2 * 1.3 ... * 2 - numbers are starting from 1.1 and stops at 2 I have done this but it gives me 4.41 instead of 67.04, what is the problem? do I need to write it using for loop? Script:

count = 1.1

while count < 2.1:
    print(count)
    count  = 0.1

print(round(count * count, 3))

CodePudding user response:

out = 1
for i in range(11,21):
    out *= i/10

print(out)

Output:

67.04425728

CodePudding user response:

I have added a final_product variable which will multiply each of the updated count value, maybe this can help:

count = 1.1
final_product = 1
while count < 2.1:
    print(count)
    final_product*=count
    count  = 0.1
print(round(final_product, 2))

You were doing everything perfectly but you need to add something which should capture the new updated value (by 0.1) and multiply to itself to get the final product i.e. 67.04.

  • Related