Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this assignment you will write functions, use functions and their appropriate parameters, and use random numbers generated by the computer. Background Phone numbers
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.
Step by Step Solution
★★★★★
3.37 Rating (147 Votes )
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started