s help me in python language
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
pls help me in python language
![carbon
12.0110
hydrogen
1.0079
охудen
15.9994
revise your program for the molecular weight of a chemical compound of hydrogen, carbon, and oxygen, so that it can take as user input a
chemical formula of the form C2H5OH for ethyl alcohol, COOHC6H40COCH3 or C9H804 for aspirin, CH3CH2CH2CH2CH2CH2CH2CH3 or
C8H18 for octane, and so forth. You should write an algorithm to analyse an input string of this form, using string indexing as in section 3.1
to look at individual characters in the string. You should accumulate the total counts of hydrogen, carbon, and oxygen in the compound, and
then use the formula in your previous section 2.12 assignment to compute the molecular weight. I suggest you use a list of three entries for
these three counts, and increment the appropriate count as you process the input string. Be careful to deal with the case when there is no
number following the letter, which means the implied number is just one, and the case, as for octane above, when the number after a letter
has more than one digit.
|
The program should keep outputting the prompt "Enter a chemical formula, or just the enter key to quit: " for the chemical formula of a new
compound, until the user presses only the enter key without a chemical formula, in which case the program should terminate. The
molecular weights should be printed with exactly four digits after the decimal point (since the atomic weights above and in section 2.12
have four decimal places).
Below is my output for the four chemical formulas above. The user input will not appear in the output used by the zyBooks comparison
tests when grading. There are also some hidden test cases.
Enter a chemical formula, or just the enter key to quit: C2H5OH
The molecular weight is 46.0688
Enter a chemical formula, or just the enter key to quit: COOHC6H4OCOCH3
The molecular weight is 180.1598
Enter a chemical formula, or just the enter key to quit: C9H8O4
The molecular weight is 180.1598
Enter a chemical formula, or just the enter key to quit: C8H18
The molecular weight is 114.2302
Enter a chemical formula, or enter key to quit:](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F976e8444-9170-46ca-a8b8-7508d328efd0%2F632153ba-173f-403f-b895-c74fc3129349%2Fo6fxb0q_processed.png&w=3840&q=75)
Transcribed Image Text:carbon
12.0110
hydrogen
1.0079
охудen
15.9994
revise your program for the molecular weight of a chemical compound of hydrogen, carbon, and oxygen, so that it can take as user input a
chemical formula of the form C2H5OH for ethyl alcohol, COOHC6H40COCH3 or C9H804 for aspirin, CH3CH2CH2CH2CH2CH2CH2CH3 or
C8H18 for octane, and so forth. You should write an algorithm to analyse an input string of this form, using string indexing as in section 3.1
to look at individual characters in the string. You should accumulate the total counts of hydrogen, carbon, and oxygen in the compound, and
then use the formula in your previous section 2.12 assignment to compute the molecular weight. I suggest you use a list of three entries for
these three counts, and increment the appropriate count as you process the input string. Be careful to deal with the case when there is no
number following the letter, which means the implied number is just one, and the case, as for octane above, when the number after a letter
has more than one digit.
|
The program should keep outputting the prompt "Enter a chemical formula, or just the enter key to quit: " for the chemical formula of a new
compound, until the user presses only the enter key without a chemical formula, in which case the program should terminate. The
molecular weights should be printed with exactly four digits after the decimal point (since the atomic weights above and in section 2.12
have four decimal places).
Below is my output for the four chemical formulas above. The user input will not appear in the output used by the zyBooks comparison
tests when grading. There are also some hidden test cases.
Enter a chemical formula, or just the enter key to quit: C2H5OH
The molecular weight is 46.0688
Enter a chemical formula, or just the enter key to quit: COOHC6H4OCOCH3
The molecular weight is 180.1598
Enter a chemical formula, or just the enter key to quit: C9H8O4
The molecular weight is 180.1598
Enter a chemical formula, or just the enter key to quit: C8H18
The molecular weight is 114.2302
Enter a chemical formula, or enter key to quit:
![digits and C, H, and O, or begins with a digit, the program will print the line "Badly formed molecular formula; try again." and then the input
prompt again. So a possible session might look like:
Enter a chemical formula, or just the enter key to quit: 14H
Badly formed molecular formula; try again.
Enter a chemical formula, or just the enter key to quit: h14
Badly formed molecular formula; try again.
Enter a chemical formula, or just the enter key to quit: H14
The molecular weight is 14.1106
Enter a chemical formula, or the enter key to quit:](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F976e8444-9170-46ca-a8b8-7508d328efd0%2F632153ba-173f-403f-b895-c74fc3129349%2F53mxjt3i_processed.png&w=3840&q=75)
Transcribed Image Text:digits and C, H, and O, or begins with a digit, the program will print the line "Badly formed molecular formula; try again." and then the input
prompt again. So a possible session might look like:
Enter a chemical formula, or just the enter key to quit: 14H
Badly formed molecular formula; try again.
Enter a chemical formula, or just the enter key to quit: h14
Badly formed molecular formula; try again.
Enter a chemical formula, or just the enter key to quit: H14
The molecular weight is 14.1106
Enter a chemical formula, or the enter key to quit:
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education