[Solved] METCSS521 Homework5

$25

File Name: METCSS521_Homework5.zip
File Size: 178.98 KB

SKU: [Solved] METCSS521 Homework5 Category: Tag:
5/5 - (1 vote)

For this week we are adding some new style requirements.

Up to this point, we have deducted for:

  • Improper naming of programs or zip container
    • Among other things, names be all lower case
  • Missing program docstring
  • Inadequate # line comments
    • Just a few in each program dont excessively comment
  • Going significantly over 80 characters for code/comment lines
  • Using CamelCase or anything other than lower case plus underscores for variables and function names.
    • CONSTANT variables are the one exception and must be all upper case.
    • Asking for input() without telling the user what is expected.
  • Especially if asking for input that will be split(). Dont make users have to check the code!
  • x = input(Enter two numbers:) # Vague
  • Printing output that isnt clearly explained (where necessary)

Starting with Homework 5, we will also be deducting for:

  • Not providing a docstrings for functions and class objects
  • Crashing uncontrolled on bad user input
  • Having too large a scope for try blocks
  • Not using format() to round output and add thousand separating commas (US standards)
  • 126 should be 123,456.13 {:,.2f}.format(123456.126)
  • Having a main() function, with no input arguments or return values
  • Not using an if __name__ == __main__ block where appropriate

Chapter 5 Exercises

5.5.1: Write a python program that does the following:

  • takes as input from the user an English sentence
  • calls the function vc_counter() that:
    • takes a string argument
    • counts the number of vowels and consonants in the string
    • returns a dictionary of the counts, using the keys total_vowels and total_consonants
  • Uses the return from vc_counter() to print the total vowels and consonants with appropriate descriptions.

Example:

Enter an English sentence: The quick brown foxs jump landed past the lazy dog!Total # of vowels in sentence: 12Total # of consonants in sentence: 29

5.5.2: Write a python program that does the following:

  • takes as input from the user a date and time (24-hour clock) as MM/DD/YYYY HH:mm:SS
    • Assume that everything must be provided with leading zeros
  • calls the function is_ validate_datetime () that:
    • takes a string argument
    • validates that the string has all the elements to be a valid date and time
    • returns 2 values:
      • Boolean true if valid or false if invalid date/time
      • None if valid or an error message string if invalid
    • If the input string is returned from the function as invalid, print the returned error message.
    • If the input string is returned from the function as valid, use input string to print following:
      • MM/DD/YYYY
      • HR:MIN:SEC
      • MM/YYYY
      • Whether the time is AM or PM

You must write your own algorithms. Do not use existing functions like datetime.strptime

Example 1:

Enter a date time (MM/DD/YYYY HR:MIN:SEC): 12/13/2020 11:31:41MM/DD/YYYY is 12/13/2020

HR:MIN:SEC is 11:31:41

MM/YYYY is 12/2020The time is AM

Example 2:

Enter a date time (MM/DD/YYYY HR:MIN:SEC): 122/04/1990 13:12:12Invalid: there can be only 12 months in a year.

Think of all possible erroneous inputs and write code to handle them.

Chapter 6 Exercise

5.6.3 Write a python program that does the following:

Prompts the user for three numbers in one request.Be sure to specify the delimiter by which a user enters those three numbers.Divides the first number by the second number and add that result to the third number.

Prints output that shows in one line the formula applied and the result of the calculation.

Validate input by:

  • Checking the user entered 3 values
  • Appropriately checking for the following errors: ValueError and ZeroDivisionError.
  • Printing descriptive error messages to the console if validation fails.
  • Remembering to have very granular testing blocks

No Example Output provided for this question.

Chapter 8 Exercise

5.8.4: Write a python program that does the following:

Prompt for a file name of text words.Words can be on many lines with multiple words per line.

Read the file and convert the words to a list.

Call a function you created called list_to_words(), that takes a list as an argument and returns a list that contains only words that occurred once in the file.

Print the results of the function with an appropriate description.

Think about everything you must do when working with a file.

No Example Output provided for this question.

Chapter 15 Exercise

5.15.5: The formula for calculating the amount of money in a savings account that begins with an initial principal value (P) and earns annual interest (i) for (n) years is: P(1 + i)nNote that i is a decimal, not a percent interest rate: .1 NOT 10%

Write a python program that does the following:

  • Prompt the user on three lines for principal, percent interest rate and number of years to invest (using descriptive prompts)
    • Use a while loop to keep prompting until entries are valid
  • Call your function calc_compound_interest() that:
    • takes the arguments principle, int_rate, years
    • uses the above formula to calculate the ending value of the account
    • returns the value
  • Call a second function calc_compound_interest_recursive() that:
    • takes the arguments principle, int_rate, years
    • calculates the value recursively calling a base calculation over and over instead of using the number of year as an exponent.
    • return that value
  • Print both values with clear descriptions and formatted with thousand commas and 2 decimal places. Then print whether the two values are equal when rounded to 4 decimal places.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] METCSS521 Homework5
$25