Question

# How much money do you think you would earn in a period of 30 days if...

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:

• The program should ask the user for a number of days. This is an integer value, and it must be a value greater than zero.
• The program must validate the input given by the user and make sure that:
• if the user enters a non-integer the program issues an error message and requests the user provides a valid input
• if the user enters a number that is zero or less than zero the program alerts the user of the mistake and requests the user enter a valid number.
• validation must be done using loops.
• The program should display a table showing what the earnings are for each day, and then show the total pay accrued by the end of the period. The output should be displayed in a dollar amount, not the number of cents.
• use either format() or the string formatters/conversion specifiers to display the table and amounts of money with 2 decimal places.

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:

• The purpose of this problem is to practice using loops and try/except.
• Please make sure to submit a well-written program. Good identifier names, useful comments, and spacing will be some of the criteria that will be used when grading this assignment.
• This assignment can be and must be solved using only the materials that have been discussed in class. Do not look for alternative methods that have not been covered as part of this course.

• correctness: the program validates input and performs calculations correctly: 40%
• complies with requirements (it properly uses loops, try/except): 40%
• code style: good variable names, comments, proper indentation and spacing : 20%

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)))
``````

#### Earn Coins

Coins can be redeemed for fabulous gifts.