Assignment 1D

Assume that you are paid on the basis of one cent the first day, two cents the second day, four cents the third day, with the daily amount continuing to double in this way. Design an algorithm and use it to write a Python program that uses loops to calculate the amount of money a person would earn over a period of time (maximum period one year) if paid in this way. The program should be implemented with a 'pre-tested loop' terminated by a sentinel like 0 or [Enter] to a "How many days?" type prompt (i.e. do NOT control the loop by asking something like "Do you want to do another calculation?" or "Do you want to quit?" etc). The user's response should be validated to ensure that the value entered falls between 1 and 366 days inclusive. (If it doesn't, the user should be requested to enter the value again). Output (for each pass through the main loop) should consist of a two column table with 'day' in the first column and 'today's salary' in the second column. At the bottom of the table the total salary should be displayed. All monetary values should be shown as dollar amounts, not cents (for example $17.50 not 1750 cents).

Notes:

  • The algorithm should be written in pseudocode (structured English).
  • Use one or more functions where sensible to do so and comment your program thoroughly.
  • Specify 2 sets of test data that will demonstrate the correct ‘normal’ operation of your program. One of those sets should be selected to demonstrate how much better it would be for you to work in July (31 days) rather than in June (30 days)! Select another 2 sets of test data that will demonstrate the ‘abnormal’ operation of your program.

Run your program using the test data you have selected and save the output it produces in a single text file.

Submit:

  • Your algorithm and test data table.
  • Source code for your Python implementation.
  • Output test file demonstrating the results of using the test data.

It is important that the output listings are not edited in any way.

Assignment 1E

Page 209 of Gaddis shows a function that can be used to determine whether a number is odd or even. Design an algorithm and use it to write a Python program that uses this function to determine how "random" the random number generator in Python actually is. (If it's truly random, on average there should be 50% odd numbers generated and 50% even numbers generated). Your program should generate 100 random numbers, test them and print the counts, then repeat this until twenty 100-number batches have been processed. At the bottom, print a sensible summary.

Notes:

  • The algorithm should be written in pseudocode (structured English)
  • Processing and printing the output for a 100-number batch should be done in a dedicated function. The 'main' function should print only the final summary.
  • Include logic in your program to prevent the processing of 'negative' numbers of seconds.
  • Is there test data for this program? If there is, show it in a table in the usual manner. If there isn't, explain instead why not, and then explain how you go about testing the program!.

Run your program using the test data (if relevant) and save the output it produces in a single text file.

Submit:

  • Your algorithm and test data table.
  • Source code for your Python implementation.

It is important that the output listings are not edited in any way.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.