Python Homework Help

Using the facilities provided by the acctmis module, write python functions to answer all of the following three questions, and store your code in a file called "area_codes.py":

Q1. get_area_codes() - this should read the web_page at https://www.bennetyee.org/ucsd-pages/area.html (Links to an external site.)

 scrape the codes from that page, and produce a dictionary (which should be stored in a global variable CODES). If the function completes successfully, then it should return the value True, if it doesn't complete, then print an error message, and return the value False. The dictionary in CODES should have as the key the area_code, and as the data a list containing the following:

  • state code (e.g. 'NJ')
  • time-zone (e.g. '-5')
  • description (e.g. "N New Jersey: Jersey City, Hackensack...")

Q2, get_state_for_code(area_code) - this should take an area code as a string (e.g. "201"), look up the entry in the CODES global variable produced by the answer to Q1, and return just the state code as a string. Eg. get_state_for_code("201') --> "NJ". If no value is found for the area code, or if the area_code is not in the right format (a string of length 3 with just numbers in it), then print an error message to the screen, and return the value None.

Q3. get_data_for_number(phone_number) - this should take a US 10-digit phone number which could be in any of the below formats, extract the area code from the number, and return all the data about that area_code as a list (i.e. the entry in the CODES variable, produced by the answer to Q1). If the phone number is not in the right format, then an error message should be printed and the result None should be returned from the function. If no entry is found for the area code, then a message should be printed, and None returned from the function. Valid formats for the number are:

  • Any integer number containing exactly 10 digits - e.g. 2014553810
  • '(XXX) XXX XXXX' - a string in this format, where X is one of the digits 0-9
  • 'XXX-XXX-XXXX' - a string in this format, where X is one of the digits 0-9 
  • 'XXXXXXXXXX' - a string in this format, where X is one of the digits 0-9 

 

Notes: You should handle reasonably expected data "errors" in your code throughout. You should use the functions provided by acctmis to do the web-page reading (and other things) by importing that module (import acctmis) at the top of your "area_codes.py" file, rather than by copying and pasting the functions into your code.

Hint: the data for the area codes on the given web page is in a table.

Get Help With a similar task to - Python Homework Help

Login to view and/or buy answers.. or post an answer

Related Questions

Similar orders to Python Homework Help
32
Views
0
Answers
Advance topics in machine learning (Kernels) 2 questions.
Any 2/3 Questions need answering on Advance topics in machine learning (Kernels). relevant notes can be shared upon request....
17
Views
0
Answers
Using R programming to perform functions and do work.
The expectations are to use R programming to answer the questions attached the file, and the result is also to be a .r file....
13
Views
0
Answers
write up a report using c programming.
Using the knowledge acquired from this module write a descriptive report to solve the programming problems listed below. The word count limit is 500 words You must include the full code implementation as appendix! I recommend you use Courier New size 1...
16
Views
0
Answers
Analyse requirements and select appropriate solutions. Design programmes that use appropriate data structures
The assignment requires you to select and implement appropriate data structures, design and implement algorithms and create the relevant software applications that will allow a user to store, update and manipulate the data relating to the operations of an...