Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part I: Date Reformatter (4 points) Write a function reformat date() that takes a string argument containing a date in one format it and returns

Part I: Date Reformatter (4 points) Write a function reformat date() that takes a string argument containing a date in one format it and returns the date in another format. Specifically, it converts an argument like 10/31/2017 (MM/DD/YYYY) to 31-OCT-17 (DD-MMM-YY). The three-letter abbreviations in the return value must be given in all capital letters: JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC. (Hint: you dont need 12 if-statements to map month numbers to these strings. Try to think of another way...) The returned day and year must be given as two-digit values, even if the first digit is a 0. The argument will not include leading zeroes. You may assume that the year is in the range 2000-2999, inclusive.

image text in transcribed

Note that the quotation marks displayed in the examples are there to emphasize that the argument and return value are strings. You should not add quotation marks to your return values.

Part II: Stock Portfolio (2 points) In addition to lists and dictionaries, Python offers another type of collection called a tuple (pronounced tupple or toople). A tuple is a container for a fixed, immutable collection of values. This means that elements inside of a tuple cannot be changed or deleted. It also means that new items cannot be added to an existing tuple. In Python, a tuple is denoted using parentheses. Here are some examples of tuples: sizes = (small, medium, large, extra large) ages = (22, 29, 25, 30, 19, 24) info = (Jane Smith, 21, 3.91) Note that we can mix data types within a single tuple. To access the elements of a tuple we can use bracket notation. For instance, the following code would print the string large on the screen: print(sizes[2])

image text in transcribed

We could represent these four stock transactions using a list of tuples: portfolio = [ (CAT, 25, 43.50, 67.75), (MSFT, 100, 87.65, 82.50), (IBM, 35, 90.15, 92.97), (APPL, 200, 175.00, 255.65) ]

Write a function stocks value() that takes a list of tuples structured in this manner and computes the total profit or loss that was realized from buying and selling the stocks. The profit or loss realized for a single stock is computed using the formula: profit or loss = # of shares (selling price purchase price) Note that the list could have as few as one tuple or as many as dozens of tuples in it. The example above has four tuples, but this is just one example. For the example above, the total profit or loss would be calculated as follows: 25 (67.75 43.50) + 100 (82.50 87.65) + 35 (92.97 90.15) + 200 (255.65 175.00) This mathematical expression is equal to 16319.95. So, the function would return 16319.95 for this input. Here is another example. If the argument to stocks value() were the following list: portfolio = [ (GOOG, 250, 325.86, 278.90), (ABC, 115, 25.60, 29.85) ] then the function would return 11251.25. Both of these examples are included in the bare bones file to help you test your code.

Part III: Are You a Permutation? (3 points) A permutation of a list or string is a rearrangement of the elements in the list or string. For example, given the list [1,2,3,4], permutations would include [2,4,1,3], [4,3,1,2] and [3,2,4,1]. Likewise, given the string dome, permutations would include edom, emod and mode. Write a function permutations() that takes a string argument, opens the file words.txt (provided on Blackboard) and returns a list consisting of all permutations of the string argument found in the file (if any). The original word should not be included in the returned list. The function may return the words in any order inside the list.

image text in transcribed

Examples: Function Call Return Value reformat date 5/17/2021 17-MAY-21 reformat date ('12/31/2000') 31-DEC-00' reformat date 9/8/2017 08-SEP-17 reformat date 8/5/2003') 05-AUG-03

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

Prepare a short profile of Henry words worth Longfellow?

Answered: 1 week ago

Question

What is RAM as far as telecommunication is concerned?

Answered: 1 week ago

Question

Question 1: What is reproductive system? Question 2: What is Semen?

Answered: 1 week ago

Question

Describe the sources of long term financing.

Answered: 1 week ago

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago