179k views
3 votes
(The python for loop) Write a program that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should ask the user for the number of days. Display a table showing what the salary was for each day and show the total pay at the end of each day in pennies. When the cumulative pay is more than $5000, display the message "It is worth earning pay at this rate if you work for at least xxx days because you just made $yyy". Finally at the end of the time period show the total pay in a dollar amount, not the number of pennies. (hint: geometric sequences)

1 Answer

1 vote

Step-by-step explanation:

days = int(input('Enter number of days: '))

total_pay = 0

current_day = 1

print('Day\tSalary\tTotal Pay')

while current_day <= days:

salary = 2 ** (current_day - 1)

total_pay += salary

print("%d\t$%.2f\t$%.2f" % (current_day, salary/100, total_pay/100))

if total_pay > 5000:

print("It is worth earning pay at this rate if you work for at least %d days because you just made $%.2f" % (current_day, total_pay/100))

current_day += 1

print("Total pay: $%.2f" % (total_pay/100))

User Lucina
by
7.8k points