Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Technology And Management Computers And Information Processing Systems For Business

Authors: Robert C. Goldstein

1st Edition

0471887374, 978-0471887379

Students also viewed these Databases questions

Question

4. Does cultural aptitude impact ones emotional intelligence?

Answered: 1 week ago