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.

How your program will be graded:

  • 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

Homework Answers

Answer #1
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)))

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Design a program that calculates the amount of money a person would earn over a period...
Design 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 salary was for each day, and then show the total pay at the end of the period. The output should be displayed in a...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts,...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts, it will present a welcome screen. You will ask the user for their first name and what class they are using the program for (remember that this is a string that has spaces in it), then you will print the following message: NAME, welcome to your Magic Number program. I hope it helps you with your CSCI 1410 class! Note that "NAME" and "CSCI...
Now we want to display which error was thrown in our voting program. ( BOTH QUESTIONS...
Now we want to display which error was thrown in our voting program. ( BOTH QUESTIONS ARE PYTHONS PROGRAMS) Add the appropriate code to the try/except statement so the exception is displayed. Run the program and, when prompted, enter the word 'old' so your output matches the output under Desired Output. # Set the variable age = input("What is your age?") # Insert a try/except statement # here when you convert the input # to a number using int() try:...
Using python, write the program below. Program Specifications: You are to write the source code and...
Using python, write the program below. Program Specifications: You are to write the source code and design tool for the following specification: A student enters an assignment score (as a floating-point value). The assignment score must be between 0 and 100. The program will enforce the domain of an assignment score. Once the score has been validated, the program will display the score followed by the appropriate letter grade (assume a 10-point grading scale). The score will be displayed as...
You must use Windows Programming(Do NOT use Console) to complete this assignment. Use any C# method...
You must use Windows Programming(Do NOT use Console) to complete this assignment. Use any C# method you already know. Create a Windows application that function like a banking account register. Separate the business logic from the presentation layer. The graphical user interface should allow user to input the account name, number, and balance. Provide TextBox objects for withdrawals and deposits. A button object should be available for clicking to process withdrawal and deposit transactions showing the new balance. Document and...
Console ================================================================                        Baseball Team Manager MENU OPTIONS 1 – Display
Console ================================================================                        Baseball Team Manager MENU OPTIONS 1 – Display lineup 2 – Add player 3 – Remove player 4 – Move player 5 – Edit player position 6 – Edit player stats 7 - Exit program POSITIONS C, 1B, 2B, 3B, SS, LF, CF, RF, P Team data file could not be found. You can create a new one if you want. ================================================================ Menu option: 2 Name: Mike Position: SS At bats: 0 Hits: 0 Mike was added....
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...
In this assignment you will write a program that compares the relative strengths of two earthquakes,...
In this assignment you will write a program that compares the relative strengths of two earthquakes, given their magnitudes using the moment magnitude scale. Earthquakes The amount of energy released during an earthquake -- corresponding to the amount of shaking -- is measured using the "moment magnitude scale". We can compare the relative strength of two earthquakes given the magnitudes m1 and m2 using this formula: f=10^1.5(m1−m2) If m1>m2, the resulting value f tells us how many times stronger m1...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT