Question: WHILE LOOPS AND FUNCTIONS IN PYTHON. Python only, please! Write an app that allows the user to enter the percentage constituents of a compound that
WHILE LOOPS AND FUNCTIONS IN PYTHON.

Python only, please!
Write an app that allows the user to enter the percentage constituents of a compound that contains carbon (C), hydrogen (H), and oxygen (O) in order to obtain the empirical formula of the compound. The empirical formula is the SIMPLEST whole number ratio that defines constituent atoms in a compound. For example, Aspirin contains 60.0% C, 4.48% H, and 35.5% O. The empirical formula could be found as follows: 1. Write a function in a module (named youFirstname,py) that takes the percentage constituents of the compound (carbon, hydrogen, oxygen) and finds the subscripts for each element based on the following algorithm: a. Start with the number of grams of each element. If percentages are given, assume that the total mass is 100 grams so that the mass of each element-the percent given . Convert the mass of each element to moles using the molar mass from the periodic table. The molar mass of oxygen is 15.994 grams per mole (g/mol), molar mass of Hydrogen 1.007 g/mol, Molar mass of C is 12.011 g/mol. These values should be shown as constants in the module. In the example above, the ratio of carbon to other elements in the compound, we compute nC as b. c. nC = perc of carbon (g) * (1 mol of C/ molar mass of C) 60.0g(1 mol of C/12.011g) 4.995 mol of C Equally, nO perc of oxygen(g) * (1 mol of C/molar mass of O) = 35.5g*(1 mol of O/15.994) = 2.220 mol of O nH perc of hydrogen (g) *(1 mol of H/ molar mass of H) 4.48g*(1 mol of H/1.007) 4.449 Divide each mole value by the smallest number of moles calculated. To do that, put the nC, no, nH in a list and find the minimum value of the list. d. nCO = 4.995/2.22 = 2.25 mol C/ 1 mol nHO 4.449/2.22 2.00 mol H/ 1 mol O Round to the nearest whole number. This is the mole ratio of the elements and is represented by subscripts in the empirical formula. In the example above, the compound has C:H:O in approximate ratio of 2:2:1 (note that this is an imperfect way of arriving at the empirical formula since the fractions [- 0.25,-0.5,-0.75] have been ignored). * How do you return the three subscripts in your function??? Put them in a list and return the list. e. 2. Write a main program (named yaurlastName.ipynb). Your main program should do the following: Create a loop (while loop) to enable the user print out the empirical formulas for five compounds. The user is provided with input boxes to enter percentage composition of the compound (carbon, hydrogen, oxygen). The total of all percentages must be 100%. Call the function from the module to compute the subscripts for carbon, hydrogen and oxygen. Print out the formula of the compound (e.g. C2H20). Hint: Use the index position of the element's subscript and concatenation for your print statement. For example, if the function receiving list is lst3, and Ist3-1,2,1], then your print should be: print ("C"+str(Ist30)+.) please complete it! a. b. c. When your program is done, it should print: Thanks for using this app! Test your program with the following data: % Carbon 52.00 13.00 35.00 C2H6O 40.92 68.54 8.63 22.83 C4H6O 40.00 48.38 % Hydrogen 16.72 ygen53.28 54.50 43.50 Emp. Formula CH20 CHO CH30 Write an app that allows the user to enter the percentage constituents of a compound that contains carbon (C), hydrogen (H), and oxygen (O) in order to obtain the empirical formula of the compound. The empirical formula is the SIMPLEST whole number ratio that defines constituent atoms in a compound. For example, Aspirin contains 60.0% C, 4.48% H, and 35.5% O. The empirical formula could be found as follows: 1. Write a function in a module (named youFirstname,py) that takes the percentage constituents of the compound (carbon, hydrogen, oxygen) and finds the subscripts for each element based on the following algorithm: a. Start with the number of grams of each element. If percentages are given, assume that the total mass is 100 grams so that the mass of each element-the percent given . Convert the mass of each element to moles using the molar mass from the periodic table. The molar mass of oxygen is 15.994 grams per mole (g/mol), molar mass of Hydrogen 1.007 g/mol, Molar mass of C is 12.011 g/mol. These values should be shown as constants in the module. In the example above, the ratio of carbon to other elements in the compound, we compute nC as b. c. nC = perc of carbon (g) * (1 mol of C/ molar mass of C) 60.0g(1 mol of C/12.011g) 4.995 mol of C Equally, nO perc of oxygen(g) * (1 mol of C/molar mass of O) = 35.5g*(1 mol of O/15.994) = 2.220 mol of O nH perc of hydrogen (g) *(1 mol of H/ molar mass of H) 4.48g*(1 mol of H/1.007) 4.449 Divide each mole value by the smallest number of moles calculated. To do that, put the nC, no, nH in a list and find the minimum value of the list. d. nCO = 4.995/2.22 = 2.25 mol C/ 1 mol nHO 4.449/2.22 2.00 mol H/ 1 mol O Round to the nearest whole number. This is the mole ratio of the elements and is represented by subscripts in the empirical formula. In the example above, the compound has C:H:O in approximate ratio of 2:2:1 (note that this is an imperfect way of arriving at the empirical formula since the fractions [- 0.25,-0.5,-0.75] have been ignored). * How do you return the three subscripts in your function??? Put them in a list and return the list. e. 2. Write a main program (named yaurlastName.ipynb). Your main program should do the following: Create a loop (while loop) to enable the user print out the empirical formulas for five compounds. The user is provided with input boxes to enter percentage composition of the compound (carbon, hydrogen, oxygen). The total of all percentages must be 100%. Call the function from the module to compute the subscripts for carbon, hydrogen and oxygen. Print out the formula of the compound (e.g. C2H20). Hint: Use the index position of the element's subscript and concatenation for your print statement. For example, if the function receiving list is lst3, and Ist3-1,2,1], then your print should be: print ("C"+str(Ist30)+.) please complete it! a. b. c. When your program is done, it should print: Thanks for using this app! Test your program with the following data: % Carbon 52.00 13.00 35.00 C2H6O 40.92 68.54 8.63 22.83 C4H6O 40.00 48.38 % Hydrogen 16.72 ygen53.28 54.50 43.50 Emp. Formula CH20 CHO CH30
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
