jeudi 11 juillet 2019

Unable to keep a variable defined

I have an assignment to create a repetition loop that exits when the condition is met. Yet, it will not allow me to fully run it due to 2 variables being unable to be defined. This is the assignment description. "Program 1. Pennies for Pay(50 points): Design a program that calculates the amount of money a person would earn over a period of time if his/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 salary was for each day, and then show the total pay at the end of the period. The output should be displayed in a dollar amount, not the number of pennies. For example if user enters 5 for total days worked, the output should be similar as:

Day                        Daily Pay
1                             $0.01
2                             $0.02
3                             $0.04
4                             $0.08
5                             $0.16
Total Pay               $0.31"

Code:

def main():
dayNumber=1
dailyPay=0.01
desiredDays=0
totalPay=0
dayNumber=float(dayNumber)
dailyPay=float(dailyPay)
desiredDays=float(desiredDays)
totalPay=float(totalPay)
...
desiredDays=int(input('Please enter how many days you wish to run this program.'))
while dayNumber<desiredDays:
print('Your total earnings are', dailyPay)
totalPay=dailyPay+dailyPay
dayNumber=dayNumber+1
dailyPay=dailyPay*2
...

I expected to get a loop that would add a dayNumber, double dailyPay, keep track of totalPay, and print out the current earnings. Instead, I get this error message:

Aucun commentaire:

Enregistrer un commentaire