Understanding how to extract digits from a multidigit 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 multidigit 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: 9780133050479
1st Edition
Authors: Robert Rufus, Laura Miller, William Hahn
Posted Date:
Students also viewed these programming questions

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...

Calculate the 90% confidence interval for the difference (mu1mu2) of two population means given the following sampling results. Population 1: sample size = 19, sample mean = 20.52, sample standard...

Branson Furniture Company has requested that you determine whether the companys ability to pay its current liabilities and longterm debts improved or deteriorated during 2012. To answer this...

Why is the green building movement good for contractors?

Draw the logic diagram for the following Boolean expressions. The diagram should correspond exactly to the equation. Assume that the complements of the inputs are not available.

A natural gas containing 95 mole% methane and the balance ethane is burned with 20.0% excess air. The stack gas which contains no unburned hydrocarbons or carbon monoxide leaves the furnace at 900?C...

Using the cost information given in the table below, assign work crews to jobs so that total cost is minimized. What is the loading for the crew (1,2, and 3) using the Hungarian method? Crew 1 2 3 A...

Wholly Donuts Ltd is a mediumsized doughnut manufacturer. 1. Apply value chain and other classifications to the costs listed below. (More than one classification may be appropriate for each cost...

Search in different methodology to survey patient in satisfaction about the hospital do like a points what is the best methodology is it by phone? or paper ? or send link by sms? Write if there is...

Predict which of these elements would have the greatest difference between the first and second ionization energies: Si, Na, P, Mg. Briefly explain your answer.

In Problems 3142, find the indicated secondorder partial derivative for each function f(x, y). f(x, y) if f(x, y) 3 ln x 1

Looking back at the CIP elevated slab formwork example at the end of the CIP concrete systems section, which of the three estimating options would be the best choice: (A) In a budget estimate. (B) ...

Which of the following species are not isoelectronic with the rest: Ar, K + , Ca 2+ , Y 3+ ?

Explain what happens to (a) The pH of a solution of phosphoric acid after the addition of solid sodium dihydrogen phosphate; (b) The percentage deprotonation of HCN in a hydrocyanic acid solution...

Jeffery Norville is a single taxpayer. His SSN is 412345670, and he lives at 5037 Circle Court, Crestview, IL 60543. His W2 for 2014 shows gross wages of $92,600 with $5,741 of social security and...

Write a while loop that uses an explicit iterator to accomplish the same thing as Exercise 7.3. Exercise 7.3. Write a foreach loop that calls the addInterest method on each BankAccount object in a...

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.

People who do very detailed work close up, such as jewellers, often can see objects clearly at much closer distance than the normal 25 cm. (a) What is the power of the eyes of a woman who can see an...

What is the far point of a person whose eyes have a relaxed power of 50.5 D?

It has become common to replace the cataractclouded lens of the eye with an internal lens. This intraocular lens can be chosen so that the person has perfect distant vision. Will the person be able...