Suppose you have a coin counting machine that provides input to your program. A bunch of...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Suppose you have a coin counting machine that provides input to your program. A bunch of mixed colns are placed into a hopper and are sorted one-by-one. The machine sends a string of characters to your program. When a penny is sorted, the character 'p' Is concatenated with the string. When a nickel is sorted 'n' Is concatenated with the string. Other colns: dimes, quarters, half-dollars all work the same way: the first letter of the name identifies the coin. Your program will read the string using the input() function and calculate the number of each type of coin, the value of each type of coin and the total monetary value represented. Coin values are: penny = $0.01, nickel= $0.05, dime= $0.10, quarter $0.25 and half-dollar= $0.50. Your output should have a neat report format as shown in the example below. Total amount calculation example: If the string is: "dapppoghppgd" the monetary value will be 0.10+0.25+0.01 +0.01+0.01 +0.05+0.25+0.50+0.01 +0.01+0.25+0.10 $1.55 Of course, we are not going to connect your program to a machine. A user at the console will type in strings. Here are some example program runs Here the input string is: dapppngheeader... Here, the Input string is: dappenahppadepdareenahrpader.... Use the input strings and the results shown above to test your own program. Frogram to count coins and calculate values Enter coin strings dapppnghppqpp Coin ‒‒‒‒ Coin Counter Report Fennies Nickels Dines Quarters Half-dollars coin ==== value Narber Anount ‒‒‒‒‒‒ ====== 7 1 $0.01 $0.05 $0.10 2 $0.25 9 50.50 I Pennies Nickels Dines Quarters Half-dollars. Program to count coins and calculate value Enter coin string: dapppnahppaoppdapppnghppqpp $ 0.75 $ 0.50 Total amount: $ 1.571 Coin Counter Report ‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒ $ 0.07 $0.05 $0.20 Value Number Amount CASIN= $ 0.14 $0.10 $0.10 4 $ 0.40 $ 1.50 $0.25 6 $0.50 2 $ 1.00 Total amount: 3.14 $0.01 14 04.05 $0.05 2 This programming problem involves lists, loops, f-strings, and accumulation. There are many Pythonic ways to solve the problem. It can be solved without using if elif but that's not a requirement. All solutions should traverse the user response string without using range () of len(). The problem can be solved in as little as 17 lines of source code (neglecting comments) if a suitable strategy is used. In my version, six of the 17 lines are print statements. TIPS: 1. There are four aspects of each coin: the character code used to represent each coin, the name of each coin, the value of each coin, and the number of each coin. If you use a separate variable for each of these, you will have 20 variables... which is quite a large number for a simple program. Think about how you would use the data structures to group these aspects to minimize the number of variables you create. It's ok to use several lists and index into them. It's ok to use the index() method to locate an item in a list. But avoid using range () and len(). 2. Counting the characters. a. One way would be to use a for loop to traverse the string .... for ein a: if c=='p': etc. b. Another way would be to use the string method: count() 3. Once you know the number of each character (i.e. coin) in the input string, you can compute the dollar amount of each coin. And once you know the dollar amount for each coin, you can compute the total. 4. The final thing you should do is work on getting the report formatted into columns. By the final thing, I mean save it for last... after you have figured out how to do the calculations correctly. Formatted print takes planning, testing, and tweaking. Study the f-string document. Study the report format shown above. How is each column justified? How many characters are used for each column? How are the "S" characters placed? Suppose you have a coin counting machine that provides input to your program. A bunch of mixed colns are placed into a hopper and are sorted one-by-one. The machine sends a string of characters to your program. When a penny is sorted, the character 'p' Is concatenated with the string. When a nickel is sorted 'n' Is concatenated with the string. Other colns: dimes, quarters, half-dollars all work the same way: the first letter of the name identifies the coin. Your program will read the string using the input() function and calculate the number of each type of coin, the value of each type of coin and the total monetary value represented. Coin values are: penny = $0.01, nickel= $0.05, dime= $0.10, quarter $0.25 and half-dollar= $0.50. Your output should have a neat report format as shown in the example below. Total amount calculation example: If the string is: "dapppoghppgd" the monetary value will be 0.10+0.25+0.01 +0.01+0.01 +0.05+0.25+0.50+0.01 +0.01+0.25+0.10 $1.55 Of course, we are not going to connect your program to a machine. A user at the console will type in strings. Here are some example program runs Here the input string is: dapppngheeader... Here, the Input string is: dappenahppadepdareenahrpader.... Use the input strings and the results shown above to test your own program. Frogram to count coins and calculate values Enter coin strings dapppnghppqpp Coin ‒‒‒‒ Coin Counter Report Fennies Nickels Dines Quarters Half-dollars coin ==== value Narber Anount ‒‒‒‒‒‒ ====== 7 1 $0.01 $0.05 $0.10 2 $0.25 9 50.50 I Pennies Nickels Dines Quarters Half-dollars. Program to count coins and calculate value Enter coin string: dapppnahppaoppdapppnghppqpp $ 0.75 $ 0.50 Total amount: $ 1.571 Coin Counter Report ‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒ $ 0.07 $0.05 $0.20 Value Number Amount CASIN= $ 0.14 $0.10 $0.10 4 $ 0.40 $ 1.50 $0.25 6 $0.50 2 $ 1.00 Total amount: 3.14 $0.01 14 04.05 $0.05 2 This programming problem involves lists, loops, f-strings, and accumulation. There are many Pythonic ways to solve the problem. It can be solved without using if elif but that's not a requirement. All solutions should traverse the user response string without using range () of len(). The problem can be solved in as little as 17 lines of source code (neglecting comments) if a suitable strategy is used. In my version, six of the 17 lines are print statements. TIPS: 1. There are four aspects of each coin: the character code used to represent each coin, the name of each coin, the value of each coin, and the number of each coin. If you use a separate variable for each of these, you will have 20 variables... which is quite a large number for a simple program. Think about how you would use the data structures to group these aspects to minimize the number of variables you create. It's ok to use several lists and index into them. It's ok to use the index() method to locate an item in a list. But avoid using range () and len(). 2. Counting the characters. a. One way would be to use a for loop to traverse the string .... for ein a: if c=='p': etc. b. Another way would be to use the string method: count() 3. Once you know the number of each character (i.e. coin) in the input string, you can compute the dollar amount of each coin. And once you know the dollar amount for each coin, you can compute the total. 4. The final thing you should do is work on getting the report formatted into columns. By the final thing, I mean save it for last... after you have figured out how to do the calculations correctly. Formatted print takes planning, testing, and tweaking. Study the f-string document. Study the report format shown above. How is each column justified? How many characters are used for each column? How are the "S" characters placed?
Expert Answer:
Answer rating: 100% (QA)
Here is the Python code No len or range function used here Thank You def main dimes quarters hal... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
A minor taxpayer who is being claimed on his parents' return is filing with the State to get back their withholding. What is the minimum amount of their standard deduction and A minor taxpayer who is...
-
The price of a zero-coupon bond is $747.25. It has a face value of $1,000 and 5 years to maturity. Calculate the approximate yield to maturity for this bond.
-
Declare and assign these variables as shown (all your code must appear in the body of the main method): String firstName = "Blueberry"; String lastName = "Strawberry"; In addition, declare and...
-
Timetrics 2016 survey of insurance professionals explores the use of technology in the industry. The file Technologies contains the responses to the question that asked what technologies these...
-
Light of a certain frequency has a wavelength of 438 run in water. What is the wavelength of this light in benzene?
-
Given the following vectors, find the inertial acceleration in the body axis system: a1 = VB+wx VB 10 0 300 ft rad VB = 0 W = 0 $2 VB = ft 0 S 0 0.3 0
-
Females Rating Males on OKCupid The OKCupid dating site provides lots of very interesting data. Figure 2.61 shows a scatterplot of the age of males that females find most attractive, based on the age...
-
Carl and Carol have salaries of $14,000 and $22,000, respectively. Their itemized deductions total $8,500. They are married and both are under age 65. a. Compute their taxable income assuming they...
-
Which job does supportive equity play in compromise, especially in cases including damage or bad behavior, and how might helpful cycles cultivate responsibility, mending, and compromise among...
-
During 2019, Jason and Vicki Hurting, who are married with two children and filing jointly, had the following tax information. Jason owns a cash-basis landscaping business, and Vicki works as a sales...
-
In general, the flow of control can be altered in two ways: selective or iterative. Selective statements provide selection around a number of statements whereas iterative statements provide...
-
Last year, Tammy opened an investment account with $6200 . At the end of the year, the amount in the account had decreased by 6.5% . How much is this decrease in dollars? How much money was in her...
-
2 0 1 -1 . Calculate determinant D= 1 -4 - -1 8 3
-
Jim Company acquired a 100% of the common stock of John Company on January 1, 2024. John Company maintains separate incorporation. Immediately following the acquisition, Jim and John had the...
-
A parcel of land 500 ft. x 300 ft. is bisected into two equal sized rectangles by a row of eucalyptus trees. How many acres are there in each portion?
-
Khadijeh recently passed away. She is divorced and her ex-husband has no claim over her assets. Her son Farrokh is 12 and has a disability (and qualifies for the dividend tax credit).He has been...
-
Define EC and valence shell EC
-
Quality Chicken grows and processes chickens. Each chicken is disassembled into five main parts. Information pertaining to production in July 2012 is: Joint cost of production in July 2012 was $50. A...
-
Exercise 10.3-4 asked how we might maintain an n-element list compactly in the first n positions of an array. We shall assume that all keys are distinct and that the compact list is also sorted, that...
-
Let p be an odd prime. A number a ? Z * p is a?quadratic residue?if the equation?x 2 =?a (mod?p)?has a solution for the unknown?x. a.?Show that there are exactly?(p???1)/2?quadratic residues,...
-
Solve the following linear program using SIMPLEX: maximize X1 + 3x2 subject to X1 X2 8 -X1 X2 -X1 + 4x2 s 2 X1, X2 0 . 3. VI VI VI AI
-
Why should projects be linked to the organisation's Strategic Plan?
-
What is the BCG matrix and how is it used?
-
Explain the role projects play in the delivery of an organisation's strategy
Study smarter with the SolutionInn App