Understanding how to extract digits from a multi-digit number in groups and by themselves (relevant for...
Fantastic news! We've Found the answer you've been seeking!
Question:
![](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2023/09/64fc713d5d158_1694265659674.jpg)
![](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2023/09/64fc714939cf5_1694265670945.jpg)
Transcribed Image Text:
Understanding how to extract digits from a multi-digit number in groups and by themselves (relevant for zyLab 3.15. NOTE: for zyLab 3.15 you MUST write a solution that uses the // (whole number division, floor division, often just called "div") and the % (modulo, remainder, often just called "mod") operators on an INTEGER NUMBER. NO USING STRINGS for the 3.15 lab assignment. However, do not toss your code out. You are going to get an additional lab assignment for this week that will ask you to solve that problem using strings. But there will be IMPORTANT RESTRICTIONS on what you can do. Why? Because using more advanced concepts and techniques we have not discussed at all is NOT a way to learn computer science. It is a way to use things you don't particularly well understand. It is not the way we teach. That is why a lot of our problems are very explicity about what to use in your solution and what NOT to use. Open a python shell window, a fresh one, do the following work that window, then save that window and SUBMIT IT with your work in it. DO NOT CLOSE THE SHELL WINDOW until you are done with this little problem. DO THIS DURING our lab time tonight. AT THE SHELL PROMPT (where you are typing all these things) Set a variable phNum to a possible phone number, for example: phNum = 1234567890 Notice that the parts of the phone number, area code, exchange, and extension, are as follows: 123 is the area code, 456 is the exchange, 7890 is the extension using this terminology It turns out it is easy to extract the "last x digits" from any integer using the remainder operator. Type the following in the shell and type what is printed below what you typed (type in and press enter key): (I did the first one for you) To Type in shell: phNum % 10 phNum % 100 phNum % 1000 phNum % 10000 phNum % 100000 phNum % 1000000 Result: 0 this retrives the last ??? (how many) digits of the number ---NOW, when you use mod to divide by a power of ten, what is the relationship between the form of the power of ten and the number of digits that are retrieved each tim? Think about it, don't goole or look it up. SO to conclude this part of the exercise, it is very easy to retrieve the last n digits from an integer with the % operator where n is the number of digits you want to get. Conclusion: OK, we can get the last certain number of digits but only the extension is at the end of the number. What to do? CHOP OFF the digits you just extracted!! To explore that, type the following in the shell and write what is printed out when you do: To Type in shell: phNum // 10 phNum // 100 phNum // 1000 phNum // 10000 phNum // 100000 phNum // 1000000 Result: this retrives the last ??? (how many) digits of the number 0 What is the relationship between the power of 10 you are dividing by and the part of the number that is "removed"? Can you explain what the pattern is and why it happens? NOW how can you use these two ideas to get the three different pieces of the phone number store in separate variables? ALSO, note that once you have the first two pieces and have removed them from the number, the remaining value is the area code, no need for any more divisions. Understanding how to extract digits from a multi-digit number in groups and by themselves (relevant for zyLab 3.15. NOTE: for zyLab 3.15 you MUST write a solution that uses the // (whole number division, floor division, often just called "div") and the % (modulo, remainder, often just called "mod") operators on an INTEGER NUMBER. NO USING STRINGS for the 3.15 lab assignment. However, do not toss your code out. You are going to get an additional lab assignment for this week that will ask you to solve that problem using strings. But there will be IMPORTANT RESTRICTIONS on what you can do. Why? Because using more advanced concepts and techniques we have not discussed at all is NOT a way to learn computer science. It is a way to use things you don't particularly well understand. It is not the way we teach. That is why a lot of our problems are very explicity about what to use in your solution and what NOT to use. Open a python shell window, a fresh one, do the following work that window, then save that window and SUBMIT IT with your work in it. DO NOT CLOSE THE SHELL WINDOW until you are done with this little problem. DO THIS DURING our lab time tonight. AT THE SHELL PROMPT (where you are typing all these things) Set a variable phNum to a possible phone number, for example: phNum = 1234567890 Notice that the parts of the phone number, area code, exchange, and extension, are as follows: 123 is the area code, 456 is the exchange, 7890 is the extension using this terminology It turns out it is easy to extract the "last x digits" from any integer using the remainder operator. Type the following in the shell and type what is printed below what you typed (type in and press enter key): (I did the first one for you) To Type in shell: phNum % 10 phNum % 100 phNum % 1000 phNum % 10000 phNum % 100000 phNum % 1000000 Result: 0 this retrives the last ??? (how many) digits of the number ---NOW, when you use mod to divide by a power of ten, what is the relationship between the form of the power of ten and the number of digits that are retrieved each tim? Think about it, don't goole or look it up. SO to conclude this part of the exercise, it is very easy to retrieve the last n digits from an integer with the % operator where n is the number of digits you want to get. Conclusion: OK, we can get the last certain number of digits but only the extension is at the end of the number. What to do? CHOP OFF the digits you just extracted!! To explore that, type the following in the shell and write what is printed out when you do: To Type in shell: phNum // 10 phNum // 100 phNum // 1000 phNum // 10000 phNum // 100000 phNum // 1000000 Result: this retrives the last ??? (how many) digits of the number 0 What is the relationship between the power of 10 you are dividing by and the part of the number that is "removed"? Can you explain what the pattern is and why it happens? NOW how can you use these two ideas to get the three different pieces of the phone number store in separate variables? ALSO, note that once you have the first two pieces and have removed them from the number, the remaining value is the area code, no need for any more divisions.
Expert Answer:
Answer rating: 100% (QA)
When you use the modulo operator to divide by a power of ten the relationship between the form of th... View the full answer
Related Book For
Forensic Accounting
ISBN: 978-0133050479
1st Edition
Authors: Robert Rufus, Laura Miller, William Hahn
Posted Date:
Students also viewed these programming questions
-
An important efficiency ratio is that known as the trade debtor collection period. This article shows that some companies are very slow at paying their bills. According to the Chairman of the...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
List three specific parts of the Case Guide, Objectives and Strategy Section (See below) that you had the most difficulty understanding. Describe your current understanding of these parts. Provide...
-
How would you apply this concepts to call center statistics? There are two numerical ways of describing quantitative variables, namely measures of location, and measures of dispersion. Measures of...
-
If 95% Tukey confidence intervals tell us to reject H0: 1 = 2 and H0: 1 = 3, will we necessarily reject H0: 2 = 3?
-
What is a no-fault auto insurance program? How do no-fault insurance affect personal injury litigation?
-
6. What is a sales order? When should a sales order be used?
-
A truck with a cost of $82,000 has an estimated residual value of $16,000, has an estimated useful life of 12 years, and is depreciated by the straight-line method. (a) Determine the amount of the...
-
The following information was taken from the accounts of Green Market, a delicatessen, at December 31, Year 2. The accounts are listed in alphabetical order, and each has a normal balance. Accounts...
-
Low Crop Prices Drag Farm Towns Down with Them: Low wheat, corn, and soybean prices mean another bad year for many Midwest farmers. In response to the above newspaper headline, what government action...
-
ABC Inc. is a manufacturing company that produces widgets. The company's production process involves three stages: production, finishing, and packaging. The following data is available for the month...
-
You have recently taken over daycare center that was under substandard leadership. Currently, the staff is unmotivated, negative, and often absent from work. You notice that there is minimal...
-
Choose an organization from the industry of your choice to discuss, illustrate, and reflect deliberately on the following: Why is it important to distinguish between "group" and "team "? What kinds...
-
The focus of data governance programs, in some capacity, is enterprise-wide data quality standards and processes. If you were a manager focusing on master data: Would you likely meet enterprise-level...
-
1) Identify and explain each component of the ANOVA model. 2) How is the F ratio obtained? 3) What role does the F ratio play?
-
Make a BCG matrix table and place the following products from Apple: iPhone, iPad, iMac, iPod, Apple TV, Apple Watch, AirPod, and HomePod. Briefly describe why you have placed the products in the...
-
Exercise 8-15 Direct Labor and Manufacturing Overhead Budgets [LO8-5, LO8-6] The Production Department of Hruska Corporation has submitted the following forecast of units to be produced by quarter...
-
Decades after the event, Johnson & Johnson (J&J), the 130-year-old American multinational, is still praised for swiftly The company indicated that its response was based on the expectations set forth...
-
Identify and discuss the four basic elements of fraud as established by common law.
-
Describe the income approach and compare it to the asset approach.
-
When using the buildup method for determining a required rate of return, what five components are commonly included? Discuss each.
-
10.9. Investco, a West Coast research company, must decide on the level of computer technology it will buy for its analysis department. Package A, a midlevel technology, would cost $2.5 million for...
-
10.6. Consider the cash flows associated with undertaking project X. a. Is this an early or later cash flow stream? b. Based on the term structure of interest rates in exercise 10.5, what is the...
-
10.8. ABC Metalworks wants to determine which model sheetcutter to purchase. Three choices are available, (1) machine 1 costs the least but must be replaced the most frequently, (2) machine 2 has...
![Mobile App Logo](https://dsd5zvtm8ll6.cloudfront.net/includes/images/mobile/finalLogo.png)
Study smarter with the SolutionInn App