Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

multiplication of numbers from while loop

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading