Hello,
I am writing a program the program is almost complete and performs almost exactly how it is supposed to. The problem I am having is I can’t get the output of the dollar amount to double each time the program runs the for loop.
Here is the program:
Money = .01
Days = int(input("Please enter number of days worked. "))
print("Days\tAmount Made")
print("----------------------")
for number in range(1, Days +1):
Amount_Made = number * Money
print(number, "\t", Amount_Made)
When the program runs, it produces a list like so:
days amount made
1 --------- .01
2 --------- .02
3 --------- .03
4 --------- .04
What I’m trying to get the output to be is:
days amount made
1 --------- .01
2 --------- .02
3 --------- .04
4 --------- .08
I managed to figure a way out here is the new code:
Money = .01
Days = int(input("Please enter number of days worked. "))
print("Days\tAmount Made")
print("----------------------")
for number in range(1, Days +1):
if number == 1:
print(number, "\t", .01)
elif number in range(2, Days +1):
Amount_Made = 2 * Money
print(number, "\t", Amount_Made)
Money = Amount_Made
Just for fun of being Monty (evil twin of Python):
>>> start = 0.01
>>> for i, value in enumerate((start, *(s for s in [start] for x in range(4) for s in [2 * s])), start=1):
... print(f'{i}----{value}')
...
1----0.01
2----0.02
3----0.04
4----0.08
5----0.16