moleculeparse = chemparse.parse_formula(molecule) #Parses the molecular formula to present the atoms and No. of atoms. Molecule here is 'C2H6O2'
print(moleculeparse) #Print the dictionary
for x,y in moleculeparse.items(): #For every key and value in dictionary
y = numpy.random.randint(0,y+1) #Randomly generate the value between 0 and y+1
if y == 0:
continue
else:
y = str(y)
print(x+y, end = "")
The above code essentially parses 'C2H6O' and puts it into a dictionary. Then for every key and value in the dictionary, the value is randomly generated.
When running this code, an example of an output can be something such as 'C1H4', this is what the print statement in the last line does. I want to be able to assign this output to a variable for later use but I'm not sure how to do this. I've assigned tried a = x+y, end = ""
but this leads to an error. Any help would be appreciated