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:
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...
-
The two-dimensional motion of a particle is defined by the relations r = 2 B cos(At/2B) and = At/ 2B, where r is expressed in meters, t in seconds, and in radians. Knowing that A and B are...
-
Create a hash table based implementation of a HashBag class. Remember, the difference is that a bag allows duplicates.
-
Below is a frequency distribution table for a hypothetical variable: a. How many of the scores for this variable have the value 2? b. What percentage of the scores has the value of 7 ? Value f% 7 5...
-
A company wants to develop a level production plan for a family of products. The opening inventory is 550 units, and a decrease to 200 units is expected by the end of the plan. The demand for each of...
-
1 2. Let A(x) = sin t + 1 dt, find A'(x) at x = 0, and 2 3. Evaluate the following definite integrals: 2 (a) (3x + 4x)dx 4 (b) xdx
-
Bong, Harry and Mallu formed a partnership to carry on the business of an ethnic store in Bangkok. They are to receive equal shares of the profits and can make drawings during a year, not exceeding...
-
The Greek letter a represents a number that determines how much output responds to unexpected changes in the price level. In this case, assume that a = $2 billion. That is, when the actual price...
-
You recently started working as a medical office assistant. You really enjoy working with patient accounts. Your supervisor mentioned there would be opportunities for advancement over the next few...
-
What must balance with the Customer Payment total in the Paid Documents row
-
If a stakeholder really wants the result of a project and is funding it, how would you characterize him or her? With both high interest and influence High interest but low influence Low interest but...
-
According to the instructions on the tax form, the tax on an income greater than $45,625 and less than $98,631 is $5467.25 plus 0.25 times the amount over $45,625. Arrange the steps in order that is...
-
Solve the equation. 2 (x+3) (x-2)(4x-3)=0
-
Based on the information presented in the introduction of thisproblem, what is a sound wave? 1) Propagation of sound particles that are different from theparticles that comprise the medium 2)...
-
What are conversion costs? What are prime costs?
-
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.
-
Comment on this statement: Dynamic modeling is about interaction.
-
Explain how objects interact by exchanging messages.
-
Describe the relationship between dynamic modeling, behavioral modeling, and structural modeling.
Study smarter with the SolutionInn App