203k views
0 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)

User Lorenzo P
by
7.7k points

1 Answer

6 votes

Step-by-step explanation:

# Ask the user for the number of days

days = int(input("How many days would you like to work? "))

# Set initial values

day = 1

totalPay = 0

# Print the table header

print('Day\t\tSalary\t\tCumulative Pay')

# Calculate the salary and cumulative pay for each day

while day <= days:

salary = (2**(day-1))/100

totalPay += salary

print(str(day) + '\t\t$' + str(salary) + '\t\t$' + str(totalPay))

day += 1

# Show the message if the cumulative pay is more than $5000

if totalPay >= 5000:

print('It is worth earning pay at this rate if you work for at least',

str(day-1), 'days because you just made $' + str(totalPay))

# Show the total pay in a dollar amount

totalPay = totalPay/100

print('\\The total pay is $' + str(totalPay))

User Ragesz
by
7.5k points