In this assignment you will write functions, use functions and their appropriate parameters, and use random...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In this assignment you will write functions, use functions and their appropriate parameters, and use random numbers generated by the computer. Background Phone numbers are everywhere. Did you know they have a set of rules that are used to define each number? This is how the switching system knows if you forgot to include an area code and how to direct calls where they need to go. Phone numbers are made up of three parts: Area Code (3 digits) - This is the code used by the system to decide which switching offices to use (well in the old days when phone numbers were tied to geographic regions). Central Office code (3 digits) - This is the code used to decided how to switch the number to different regions withing the switching office's control (well again in the old days). The first two digits were originally based on the office's name. Which is why phones have letters tied to the numbers. ⚫ Line number (4 digits) - This is your unique number to your phone line that you have. In fact, in the really old days, you would only need these 4 digits to call a line. And even in the early days, a phone line number would be for a whole street and everyone on the same street (4-5 houses) would share the same line number. A phone number is created by placing all of the parts together area code first, office code next, and finally the line number. However just having all of the digits together makes it difficult to read. Such as: 2082823215 So, we tend to give formatting to the number to make it easier to read such as parenthesis around the area code and placing a hyphen between the office and line numbers like this: (208) 282-3215 In case you might be wondering why phone numbers are the length they are (7 digits without the area code) this is because your short-term memory can only store 5-9 object (or in this case digits). So, 7 was safely in the middle. This was intended so that a person could hear a phone number and remember it easily. Of course, now our phones do it so there is no reason to remember phone numbers. In fact, most people now days cannot remember more than just a few phone numbers. Now a days, phone numbers follow the same pattern even though the numbers are no longer tied to a geographic region. Which comes from people moving across states and keeping their numbers. Instructions You will be creating a program that will use random numbers to create a set of possible phone numbers. To use the application, the user will enter a number of phone numbers to print. Then using pseudo random number generation available using the random module, the program will display to the user a specified number of phone numbers. Create a Python script: 1. Name the script phone_maker.py 2. Write code to create the following functionality a. Import the random library b. Create a function named get_number_to_generate which accepts nothing (has no parameters) and prompts the user for the number of phone numbers to generate. This function needs to return an integer representation of the user's response. c. Create a function named get_line_number which accepts nothing (no parameters) and returns an integer representation of a line number in the appropriate range. i. You must use the randrange function. 1. Do not use the randint function. ii. The values must be between 0 and 9999 (inclusive). d. Create a function named get_area_code which accepts an integer of the starting number of the area code and returns an integer representation of an area code in the appropriate range. i. You must use the randrange function. 1. Do not use the randint function. ii. The area code must follow the following rules: 1. The first digit of the area code must be (parameter) Minimum Maximum value given value value the number passed in the parameter. a. If the parameter contains a 2, then the values could possibly be 217, 208, or 200 3 300 319 5 500 519 6 600 619 9 900 919 2 200 219 2. The last two digits must fall between 00 and 19 (inclusive). 3. The area code must be a 3-digit number. a. Assuming N is the given number, the acceptable values are: N00-N19 b. See the table for more examples; Note: Technically any area code ending in 11 would be illegal, but we will ignore this rule. For example: 911 is an acceptable area code in our rules. e. Create a function named get_office_code which accepts an integer of the starting number of the office code and returns an integer representation of an office code in the appropriate range. i. You must use the randrange function. 1. Do not use the randint function. The office code must follow the following rules: (parameter) Minimum Maximum 1. The first digit of the office code must be the number passed in the value given value value 3 320 399 5 520 599 parameter. 6 620 699 a. If the parameter contains a 2, then the values could possibly 9 920 999 2 220 299 be 257, 228, or 260 2. The last two digits must fall between 20 and 99 (inclusive). 3. The office code must be a 3-digit number. a. Assuming N is the given number, the acceptable values are: N20-N99 b. See the table for more examples; f. For each number that the user requested, you will need to call each function appropriately and as needed to finish the code. i. Create a random number from 2-9 (inclusive) and using the get_area_code function, get and store the area code of the number. 1. 000-199 are reserved for toll numbers and system codes. ii. Create a different random number from 2-9 (inclusive) and using the get_office_code function, get and store the office code of the number. iii. Calling the get_line_number function, get the value for the line number. iv. Then print the phone number from these three values. v. The number should be in the following format: (area code) office_code-line_number For example: Hints: (208) 282-3215 (916) 737-2592 ⚫ You can use the format function to specify how many digits am integer will fill. Consult the slides from week 1 for formatting with padding. vi. You do not have to match my format, but the output should be nicely formatted. Example outputs: How many phone numbers should I show? 3 Here are the 3 random phone numbers. (918) 359-0982 (810) 673-0134 (204) 541-0475 How many phone numbers should I show? 2 Here are the 2 random phone numbers. (418) 936-6061 (818) 297-0215 How many phone numbers should I show? 5 Here are the 5 random phone numbers. (310) 858-9028 (304) 976-0660 (200) 495-4661 (508) 530-7307 (509) 466-2141 Tips: You may find it useful, for testing purposes, to temporarily assign a seed at the start of your program. If you do this, the values will not change and you can check for patterns. Use the following code to do this: random.seed(3) If you use the seed of 3, and you only get random area codes with a starting digit of 2, you should get the following: 207, 218, 217, 204, 211, 219, 215, etc. If you use the seed of 3, and you only get random office codes with a starting digit of 2, you should get the following: 250, 295, 289, 236, 267, 297, 280, etc. If you use the seed of 3, and you only get a random line numbers, you should get the following: 3898, 9709, 8916,2136, 6061, 9894, 7766, etc. Now if you use the seed of 3, and you a random hour then a random minute, you should get the following: 07:37, 17:08, 11:58, 19:30 Note: Technically any area code ending in 11 would be illegal, but we will ignore this rule. For example: (911) 911-9111 is an acceptable number in our rules. Scoring 1. 5%- Compiles without errors 2. 3%- Imports the correct module at the top of the file. 3. 7% Has a function named get_number_to_generate and has no parameters. Prompts the user and returns the correct data type. 4. 17% - Has a function named get_area_code() and has correct parameters. correctly get area code using random and parameter; uses the randrange function correctly; returns the correct data type. 5. 17% - Has a function named get_office_code() and has correct parameters. correctly get office code using random and parameter; uses the randrange function correctly; returns the correct data type. 6. 15% Has a function named get_line_number() and has no parameters. correctly get line using random; uses the randrange function correctly; returns the correct data type. 7. 6%- Generates random numbers for start of area and office codes 8. 15%-Correctly generates a list of phone numbers from functions. calls the appropriate function and the correct way. 9. 5% Presents list back to the user in an appropriate way. 10. 10% - Meaningful comments: This includes your header block with your name at the top. This includes proper function comments. In this assignment you will write functions, use functions and their appropriate parameters, and use random numbers generated by the computer. Background Phone numbers are everywhere. Did you know they have a set of rules that are used to define each number? This is how the switching system knows if you forgot to include an area code and how to direct calls where they need to go. Phone numbers are made up of three parts: Area Code (3 digits) - This is the code used by the system to decide which switching offices to use (well in the old days when phone numbers were tied to geographic regions). Central Office code (3 digits) - This is the code used to decided how to switch the number to different regions withing the switching office's control (well again in the old days). The first two digits were originally based on the office's name. Which is why phones have letters tied to the numbers. ⚫ Line number (4 digits) - This is your unique number to your phone line that you have. In fact, in the really old days, you would only need these 4 digits to call a line. And even in the early days, a phone line number would be for a whole street and everyone on the same street (4-5 houses) would share the same line number. A phone number is created by placing all of the parts together area code first, office code next, and finally the line number. However just having all of the digits together makes it difficult to read. Such as: 2082823215 So, we tend to give formatting to the number to make it easier to read such as parenthesis around the area code and placing a hyphen between the office and line numbers like this: (208) 282-3215 In case you might be wondering why phone numbers are the length they are (7 digits without the area code) this is because your short-term memory can only store 5-9 object (or in this case digits). So, 7 was safely in the middle. This was intended so that a person could hear a phone number and remember it easily. Of course, now our phones do it so there is no reason to remember phone numbers. In fact, most people now days cannot remember more than just a few phone numbers. Now a days, phone numbers follow the same pattern even though the numbers are no longer tied to a geographic region. Which comes from people moving across states and keeping their numbers. Instructions You will be creating a program that will use random numbers to create a set of possible phone numbers. To use the application, the user will enter a number of phone numbers to print. Then using pseudo random number generation available using the random module, the program will display to the user a specified number of phone numbers. Create a Python script: 1. Name the script phone_maker.py 2. Write code to create the following functionality a. Import the random library b. Create a function named get_number_to_generate which accepts nothing (has no parameters) and prompts the user for the number of phone numbers to generate. This function needs to return an integer representation of the user's response. c. Create a function named get_line_number which accepts nothing (no parameters) and returns an integer representation of a line number in the appropriate range. i. You must use the randrange function. 1. Do not use the randint function. ii. The values must be between 0 and 9999 (inclusive). d. Create a function named get_area_code which accepts an integer of the starting number of the area code and returns an integer representation of an area code in the appropriate range. i. You must use the randrange function. 1. Do not use the randint function. ii. The area code must follow the following rules: 1. The first digit of the area code must be (parameter) Minimum Maximum value given value value the number passed in the parameter. a. If the parameter contains a 2, then the values could possibly be 217, 208, or 200 3 300 319 5 500 519 6 600 619 9 900 919 2 200 219 2. The last two digits must fall between 00 and 19 (inclusive). 3. The area code must be a 3-digit number. a. Assuming N is the given number, the acceptable values are: N00-N19 b. See the table for more examples; Note: Technically any area code ending in 11 would be illegal, but we will ignore this rule. For example: 911 is an acceptable area code in our rules. e. Create a function named get_office_code which accepts an integer of the starting number of the office code and returns an integer representation of an office code in the appropriate range. i. You must use the randrange function. 1. Do not use the randint function. The office code must follow the following rules: (parameter) Minimum Maximum 1. The first digit of the office code must be the number passed in the value given value value 3 320 399 5 520 599 parameter. 6 620 699 a. If the parameter contains a 2, then the values could possibly 9 920 999 2 220 299 be 257, 228, or 260 2. The last two digits must fall between 20 and 99 (inclusive). 3. The office code must be a 3-digit number. a. Assuming N is the given number, the acceptable values are: N20-N99 b. See the table for more examples; f. For each number that the user requested, you will need to call each function appropriately and as needed to finish the code. i. Create a random number from 2-9 (inclusive) and using the get_area_code function, get and store the area code of the number. 1. 000-199 are reserved for toll numbers and system codes. ii. Create a different random number from 2-9 (inclusive) and using the get_office_code function, get and store the office code of the number. iii. Calling the get_line_number function, get the value for the line number. iv. Then print the phone number from these three values. v. The number should be in the following format: (area code) office_code-line_number For example: Hints: (208) 282-3215 (916) 737-2592 ⚫ You can use the format function to specify how many digits am integer will fill. Consult the slides from week 1 for formatting with padding. vi. You do not have to match my format, but the output should be nicely formatted. Example outputs: How many phone numbers should I show? 3 Here are the 3 random phone numbers. (918) 359-0982 (810) 673-0134 (204) 541-0475 How many phone numbers should I show? 2 Here are the 2 random phone numbers. (418) 936-6061 (818) 297-0215 How many phone numbers should I show? 5 Here are the 5 random phone numbers. (310) 858-9028 (304) 976-0660 (200) 495-4661 (508) 530-7307 (509) 466-2141 Tips: You may find it useful, for testing purposes, to temporarily assign a seed at the start of your program. If you do this, the values will not change and you can check for patterns. Use the following code to do this: random.seed(3) If you use the seed of 3, and you only get random area codes with a starting digit of 2, you should get the following: 207, 218, 217, 204, 211, 219, 215, etc. If you use the seed of 3, and you only get random office codes with a starting digit of 2, you should get the following: 250, 295, 289, 236, 267, 297, 280, etc. If you use the seed of 3, and you only get a random line numbers, you should get the following: 3898, 9709, 8916,2136, 6061, 9894, 7766, etc. Now if you use the seed of 3, and you a random hour then a random minute, you should get the following: 07:37, 17:08, 11:58, 19:30 Note: Technically any area code ending in 11 would be illegal, but we will ignore this rule. For example: (911) 911-9111 is an acceptable number in our rules. Scoring 1. 5%- Compiles without errors 2. 3%- Imports the correct module at the top of the file. 3. 7% Has a function named get_number_to_generate and has no parameters. Prompts the user and returns the correct data type. 4. 17% - Has a function named get_area_code() and has correct parameters. correctly get area code using random and parameter; uses the randrange function correctly; returns the correct data type. 5. 17% - Has a function named get_office_code() and has correct parameters. correctly get office code using random and parameter; uses the randrange function correctly; returns the correct data type. 6. 15% Has a function named get_line_number() and has no parameters. correctly get line using random; uses the randrange function correctly; returns the correct data type. 7. 6%- Generates random numbers for start of area and office codes 8. 15%-Correctly generates a list of phone numbers from functions. calls the appropriate function and the correct way. 9. 5% Presents list back to the user in an appropriate way. 10. 10% - Meaningful comments: This includes your header block with your name at the top. This includes proper function comments.
Expert Answer:
Related Book For
Modern Database Management
ISBN: 978-0133544619
12th edition
Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi
Posted Date:
Students also viewed these programming questions
-
Introduction In this assignment you will write a small C program to read the coefficients of a third degree equation, and use a numerical integration method for calculating a numerical value of a...
-
In this Assignment you examine the target customer using your CSR Tool Belt including the life stages of the targeted customer. The better you are at understanding who the targeted customer is, the...
-
In this assignment you are going to prepare payroll accounting entries, complete payroll records, and prepare payroll tax returns for a Company that started operations on October 1 of the current...
-
Simplify the expressions in Problems 3138. (3x - 1) (x + 3x - 2)
-
The Stereo Warehouse in Georgetown sells stereo sets, which it orders from Fuji Electronics in Japan. Because of shipping and handling costs, each order must be for five stereos. Because of the time...
-
Harry is a trader selling goods on credit. His financial year ends on 31 December. The balances on his books on 1 January 203 included the following: $ Provision for doubtful debts...
-
Consider the following dataset Fit a regression line using the method of least squares. Determine \(r, b_{1}\), and \(b_{0}\). i 1 xi 23 2 Yi 26 -6 3 7. 91 4 6
-
Madison Services Company had the following transactions during the month of April: Apr. 2. Issued Invoice No. 201 to Triple Play Corp. for services rendered on account, $345. 3. Issued Invoice No....
-
Explain three (3) fundamentals of digital applications in a workplace What are the key digital applications that can be used in organisations? Explain three (3) key features of digital applications...
-
Four pesticides used in dormant California orchards are chlorpyrifos, diazinon, methidathion, and parathion. Environmental Science & Technology (Oct. 1993) reported the number of applications of...
-
Critically discuss why business and government in SA should interdependently govern according to strict values and ethics.
-
Write the body for a function that replaces each copy of an item in a stack with another item. Use the following specification. (This function is in the client program.) ReplaceItem(StackType& stack,...
-
In a sample of 80 light bulbs, the mean lifetime was 1217 hours. Assume the population standard deviation is 52 hours. a. Find a 95\% confidence interval for the mean lifetime of this type of light...
-
Write C++ code for an FIR filter using a class to implement the filter. Implement as many member functions as possible as inline functions. Measure the execution time of the filter and compare to the...
-
Perform a test for ARCH effects.
-
An Unsorted List ADT is to be extended by the addition of function Tail, which has the following precondition and postcondition: Precondition: list has been initialized and is not empty....
-
1. GoAnyWhere Cases Ltd, makes a number of different suitcases. For each Family Suitcase the following applies: Questions The contribution margin per Family Suitcase in dollars is? The contribution...
-
The manager for retail customers, Katie White, wants to hear your opinion regarding one business offer she has received from an entrepreneur who is starting a mobile phone app called Easy Money. The...
-
The Pine Valley databases for this textbook (one small version illustrated in queries throughout the text and a larger version) are available to your instructor to download from the text's Web site....
-
Consider the two E-R diagrams in Figure 2-25, which represent a database of community service agencies and volunteers in two different cities (A and B). For each of the following three questions,...
-
Determine the relationships among the four relations in Figure 7-17. List primary keys for each relation and any foreign keys necessary to establish the relationships and maintain referential...
-
In a two-tailed hypothesis test of a claim about a proportion, the P-value is the area to the right of the standard score, z. Decide whether the statement makes sense (or is clearly true) or does not...
-
Find a news article or research report that describes (perhaps not explicitly) a hypothesis test for a population proportion. Attach the article and summarize the method used.
-
The claim of p < 0.25 can never be supported if the sample proportion p is greater than 0.25. Decide whether the statement makes sense (or is clearly true) or does not make sense (or is clearly...
Study smarter with the SolutionInn App