Question: please read the question carefully For this problem you must write a program that can extract the cost of, for example, one chocolate bar when


please read the question carefully
For this problem you must write a program that can extract the cost of, for example, one chocolate bar when given a sentence like How much did 25 chocolate bars cost? $63.75! Your program must first read a sentence from input. It should then use slicing to get the number of items and the total cost, and convert those values from strings into numbers. Finally, your program must calculate and print the cost of a single item. The output of your program should look like this: 1 Question: How much did 25 chocolate bars cost? $63 $2.55 2 3 Your program must still work if the sentence contains a different number, cost, or type of items: 1 Question: How much did 10 cans of cola cost? $35.0 2 $3.50 3 For this problem, you may assume that the number of items is always 2 digits (that is, it is between 10 and 99 ) and occurs after the phrase 'How much did '. You may also assume that the total cost is always between 10 and 99 dollars with cents (in the form of two digits), and appears at the end of a sentence (followed with an exclamation mark). Hint You might want to convert the amout from dollars and cents into a whole number of cents, and use integer division (/ /) and modulus (%) to separate out the dollar and cent amounts
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
