Concept explainers
# PART 1 - Complete the function below to deocompose
# a compound formula written as a string
# in a dictionary
######################################################
def mol_form(compound_formula):
"""(str) -> dictionary
When passed a string of the compound formula, returns a dictionary
with the elements as keys and the number of atoms of that element as values.
>>> mol_form("C2H6O")
{'C': 2, 'H': 6, 'O': 1}
>>> mol_form("CH4")
{'C': 1, 'H': 4}
"""
# TODO your code here
######################################################
# PART 2 - Complete the function below that takes two
# tuples representing one side of a
# chemical equation and returns a dictionary
# with the elements as keys and the total
# number of atoms in the entire expression
# as values.
######################################################
def expr_form(expr_coeffs,expr_molecs):
"""
(tuple (of ints), tuple (of dictionaries)) -> dictionary
This function accepts two input tuples that represent a chemical expression,
or one side of a chemical equation. The first tuple contains integers that
represent the coefficients for molecules within the expression. The second
tuple contains dictionaries that define these molecules. The molecule
dictionaries have the form {'atomic symbol' : number of atoms}. The order
of the coefficients correspond to the order of molecule dictionaries.
The function creates and returns a dictionary containing all elements within
the expression as keys and the corresponding number of atoms for each element
within the expression as values.
For example, consider the expression 2NaCl + H2 + 5NaF
>>> expr_form((2,1,5), ({"Na":1, "Cl":1}, {"H":2}, {"Na":1, "F":1}))
{'Na': 7, 'Cl': 2, 'H': 2, 'F': 5}
"""
# TODO your code here
########################################################
# PART 3 - Check if two dictionaries representing
# the type and number of atoms on two sides of
# a chemical equation contain different
# key-value pairs
########################################################
def find_unbalanced_atoms(reactant_atoms, product_atoms):
"""
(Dict,Dict) -> Set
Determine if reactant_atoms and product_atoms contain equal key-value
pairs. The keys of both dictionaries are strings representing the
chemical abbreviation, the value is an integer representing the number
of atoms of that element on one side of a chemical equation.
Return a set containing all the elements that are not balanced between
the two dictionaries.
>>> find_unbalanced_atoms({"H" : 2, "Cl" : 2, "Na" : 2}, {"H" : 2, "Na" : 1, "Cl" : 2})
{'Na'}
>>> find_unbalanced_atoms({"H" : 2, "Cl" : 2, "Na" : 2}, {"H" : 2, "Na" : 2, "Cl" : 2})
set()
>>> find_unbalanced_atoms({"H" : 2, "Cl" : 2, "Na" : 2}, {"H" : 2, "F" : 2, "Cl" : 2})
{'F', 'Na'}
"""
# TODO your code here
########################################################
# PART 4 - Check if a chemical equation represented by
# two nested tuples is balanced
########################################################
def check_eqn_balance(reactants,products):
"""
(tuple,tuple) -> Set
Check if a chemical equation is balanced. Return any unbalanced
elements in a set.
Both inputs are nested tuples. The first element of each tuple is a tuple
containing the coefficients for molecules in the reactant or product expression.
The second element is a tuple containing strings of the molecules within
the reactant or product expression. The order of the coefficients corresponds
to the order of the molecules. The function returns a set containing any
elements that are unbalanced in the equation.
For example, the following balanced equation
C3H8 + 5O2 <-> 4H2O + 3CO2
would be input as the following two tuples:
reactants: ((1,5), ("C3H8","O2"))
products: ((4,3), ("H2O","CO2"))
>>> check_eqn_balance(((1,5), ("C3H8","O2")),((4,3), ("H2O","CO2")))
set()
Similarly for the unbalanced equation
C3H8 + 2O2 <-> 4H2O + 3CO2
would be input as the following two tuples:
reactants: ((1,2), ("C3H8","O2"))
products: ((4,3), ("H2O","CO2"))
>>> check_eqn_balance(((1,2), ("C3H8","O2")),((4,3), ("H2O","CO2")))
{'O'}
"""
#TODO your code here
Step by stepSolved in 4 steps with 3 images
- # PART 1 - Complete the function below to deocompose# a compound formula written as a string# in a dictionary######################################################import chemparse def mol_form(compound_formula): """(str) -> dictionary When passed a string of the compound formula, returns a dictionary with the elements as keys and the number of atoms of that element as values. >>> mol_form("C2H6O") {'C': 2, 'H': 6, 'O': 1} >>> mol_form("CH4") {'C': 1, 'H': 4} """ print((chemparse.parse_formula(compound_formula))) mol_form("C2H6O")mol_form("CH4") ####################################################### PART 2 - Complete the function below that takes two # tuples representing one side of a# chemical equation and returns a dictionary# with the elements as keys and the total# number of atoms in the entire expression# as values.######################################################…arrow_forwardPointers and references are fully equivalent True Falsearrow_forwardDeclare a student structure that contains : Student's first and last nameStudent IDCreate the following functions: getStudentInfo(void) Declares a single student, uses printf()/scanf() to get inputReturns the single student backprintStudentInfo(student_t *st_ptr) Takes the pointer to a student (to avoid making a copy)Prints out all of the student informationDeclare an array of five studentsUsing a for loop and getStudentInfo() function, get input of all the studentsUsing a for loop and printStudentInfo() function, print all the output of all students.arrow_forward
- # PART 1 - Complete the function below to deocompose# a compound formula written as a string# in a dictionary######################################################import chemparse def mol_form(compound_formula): """(str) -> dictionary When passed a string of the compound formula, returns a dictionary with the elements as keys and the number of atoms of that element as values. >>> mol_form("C2H6O") {'C': 2, 'H': 6, 'O': 1} >>> mol_form("CH4") {'C': 1, 'H': 4} """ print((chemparse.parse_formula(compound_formula))) mol_form("C2H6O")mol_form("CH4") ####################################################### PART 2 - Complete the function below that takes two # tuples representing one side of a# chemical equation and returns a dictionary# with the elements as keys and the total# number of atoms in the entire expression# as values.######################################################…arrow_forwardPlease due in C++ If possible can explain what should I put in StudentInfo.h file what in StudentInfo.c Thank youarrow_forwardtypedef _people { int age; char name[ 32 ] ; } People_T ; People_T data [ 3 ]; Using string lib function, Assign 30 and Cathy to the first cell, Assign 40 and John to the second cell and Assign 50 and Tom to the third cell People_T *ptr ; Declare a pointer pointing to the structure data and print the age and name using the pointer. your output can be : 30 Cathy 40 John 50 Tomarrow_forward
- Please complete the following guidelines and hints. Using C language. Please use this template: #include <stdio.h>#define MAX 100struct cg { // structure to hold x and y coordinates and massfloat x, y, mass;}masses[MAX];int readin(void){/* Write this function to read in the datainto the array massesnote that this function should return the number ofmasses read in from the file */}void computecg(int n_masses){/* Write this function to compute the C of Gand print the result */}int main(void){int number;if((number = readin()) > 0)computecg(number);return 0;}Testing your workTypical Input from keyboard:40 0 10 1 11 0 11 1 1Typical Output to screen:CoG coordinates are: x = 0.50 y = 0.50arrow_forwardC# helparrow_forwardIn C, in order to do operations to the data being referenced by a pointer you would need to use the (*) operator, which is called ______________ operator.arrow_forward
- Game of Hunt in C++ language Create the 'Game of Hunt'. The computer ‘hides’ the treasure at a random location in a 10x10 matrix. The user guesses the location by entering a row and column values. The game ends when the user locates the treasure or the treasure value is less than or equal to zero. Guesses in the wrong location will provide clues such as a compass direction or number of squares horizontally or vertically to the treasure. Using the random number generator, display one of the following in the board where the player made their guess: U# Treasure is up ‘#’ on the vertical axis (where # represents an integer number). D# Treasure is down ‘#’ on the vertical axis (where # represents an integer number) || Treasure is in this row, not up or down from the guess location. -> Treasure is to the right. <- Treasure is to the left. -- Treasure is in the same column, not left or right. +$ Adds $50 to treasure and no $50 turn loss. -$ Subtracts…arrow_forwardPointers can be compared using the == operator. A) True B) Falsearrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education