+ 2

My Output : 10737418.23 It's must be : 10737418.24 What is the wrong??

My Output : 10737418.23 It's must be : 10737418.24 What is the wrong?? s=0 for i in range(30): s+=0.01*(2**i) print(s) https://code.sololearn.com/cmE2O28iF60c/?ref=app

11th Mar 2022, 10:51 PM
hanan nassar
hanan nassar - avatar
2 Answers
+ 6
range(30+1) as 30 is not included. However you don't need a loop in this task, simply calculate penny*2**days
11th Mar 2022, 10:59 PM
Lisa
Lisa - avatar
+ 1
The Q: Exponentiation is the raising of one number to the power of another. This operation is performed using two asterisks **. Let's use exponentiation to solve a known problem. You are offered a choice of either $1.000.000 or $0.01 (one penny) doubled every day for 30 days (the resulting amount is doubled every day). Task: Write a program to calculate the amount that will result from the doubling to understand which choice results in a larger amount. Hint: Let's see how exponentiation can be useful to perform the calculation. For example, if we want to calculate how much money we will have on the 5th day, we can use this expression: 0.01*(2**5) = 0.32 dollars (multiply the penny by 2 raised to the power of 5).
11th Mar 2022, 10:52 PM
hanan nassar
hanan nassar - avatar