How much money do you think you would earn in a period of 30 days if you were paid as follows: one cent for the first day, two cents for the second day, four cents for the third day, eight cents for the fourth day, and so on (i.e. your salary doubles each day)? Do you think you would make very little money, just a few dollars, at the end of the 30-day period? Let us write a program to find out!
Details:
Here is a sample run:
Enter the number of days: 10 Day Pennies 1 $0.01 2 $0.02 3 $0.04 4 $0.08 5 $0.16 6 $0.32 7 $0.64 8 $1.28 9 $2.56 10 $5.12 The total salary for 10 days is $10.23
Notes:
How your program will be graded:
Language = python 3
n=0
#loop until user gives valid input
while(True):
try:
n=int(input("Enter number of days: "))
if(n>0):
break
else:
print("Number of days must be greater than 0. Try again")
except:
print("Invalid input. Try again")
print("Day\tPennies")
total=1
print("1\t$"+str(round(total/100,2)))
#iterating for given days and printing the salary
for i in range(2,n+1):
total=total + total
print(str(i)+"\t$"+str(round(total/100,2)))
print("Total salary for ",n," days is $"+str(round(total/100,2)))
Get Answers For Free
Most questions answered within 1 hours.