17 Oct No.1: The following dictionary of dates and stock prices is defined in the scaffold below: prc_dic = { 3000-01-15:
No.1:
Given this dictionary:
1. Define a variable sorted_keys
that will contains the keys of prc_dic
in ascending order. Use a list comprehension to do this in a single line The following references might help:
-
list.sort
method : https://docs.python.org/3/library/stdtypes.html#list.sort -
sorted
builtin : https://docs.python.org/3/library/functions.html#sorted
2. Replace the prc_dic
key for 3000-01-15
with 2020-01-15
. Do this in one line and without explicitly writing the value 7.0400
.
No.2:
All you need to do is to submit the contents of the yf_example3.py
module, which you will create during this code challenge. We will provide you with a solution to this challenge later.
Coding (in PyCharm)
For this code challenge, you will create a new module under the toolkit
project folder. This module will be called yf_example3.py
. The purpose of this module is to download stock price data for Qantas for a given year and save the information in a CSV file. Follow the steps below to create this module.
Note: When marking this module, we will not consider the docstrings you create. Although the docstrings will not be marked, please create both a module docstring and a function docstring.
The diagram below presents the location of the relevant files and folders:
Follow the steps below to create and run this module.
-
Create a new module, called
yf_example3.py,
inside thetoolkit
project folder. Open this module in PyCharm. -
Write a simple module docstring containing the name of the module and a once sentence summarising its purpose. This docstring will not be marked.
-
Create the import statements. This module should import:
-
The
os
module -
The
toolkit_config
module. This module should be imported under the aliascfg
-
The
yf_example2
module (see location in the diagram above) without an alias
-
-
Define the function
qan_prc_to_csv
with its parameter and docstring (the docstring will not be marked):-
This function takes a single (mandatory) parameter called
year
, an integer. -
Purpose: Download Qantas stock prices for a given year into a CSV file
-
The name of this file will be
qan_prc_YYYY.csv
, where theYYYY
stands for the year inyear
. -
This file will be saved under the
data
folder. Remember that the location of this folder is already in thetoolkit_config
module.
-
-
Complete the body of this function so that
qan_prc_to_csv
making sure that it uses theyf_example2.yf_prc_to_csv
to download only the prices from January 1 to December 31 of the year inyear
. The location of the CSV file should be determined inside the function. -
Include the
if __name__ == "__main__"
statement at the end of the module and include a test case (or example). This test case will download the data foryear=2020
. -
Run the module and examine the downloaded data
Below is a step by step description of what should happen when you call the function qan_prc_to_csv(year=2020)
inside this module:
-
Variables with the start and ending period for the
yf_example2.yf_prc_to_csv
are created inside the function. In this case, the period is from2020-01-01
to2020-12-31
. -
Download the data for this period and
tic='QAN.AX'
. -
Create the name of the output file. In this case,
qan_prc_2020.csv
. -
Create a path variable making sure that this file will be inside the
data
folder. -
Save the downloaded data.
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.
About Wridemy
We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.
How It Works
To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Are there Discounts?
All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.