Search code examples
pythonchemistry

Chemistry: TypeError: can only concatenate str (not "float") to str - I do not find any helpful answers here


Unfortunately, I'm stuck at this problem albeit it surely seems utterly ridiculous to you guys. I hope you can help me.

This would be the code: (I have no idea how to show it correctly)

g = input("Gebe hier das aktuelle Volumen von HCl in ml ein: ") ### ANALYT  ###
print("Das aktuelle Volumen von HCl ist", g, "ml")              ### TITRANT ###

pH_Anfang = input( "Gebe hier den ursprünglichen pH-Wert des Titranten ein: ")

v  = input("Gebe hier das aktuelle Volumen von NaOH in ml ein: ")
print("Das aktuelle Volumen von NaOH ist",v, "ml")

Anzahl_mol_von_HCl = float(g)* 10**(-3)*0.1
#M             =           0.005      mol

Anzahl_mol_von_NaOH = float(v)*10**(-3)*0.1
#M             =           10^(-4) *v mol
#Bsp. mit 48   =           0.0048     mol

# pH = pKs -    -log(   (Anzahl mol von HCl - Anzahl mol von NaOH)        /       gesamtes 
Volumen in L )
# pH = 14 -     -log(   (0.005 mol - 10^(-4)*V mol)                       /       V in L                
)
# pH = 14 -     log(  ( (0.005 mol - 10^(-4)*V mol)                       /       V in L        
)^(1)   )
# 50 ml HCl = 0.05 L und 48 ml NaOH = 0.048 L; Total= 0.098L;                                                   
pH laut ph.lattelog.com/titrage = 2.69019608
 
berechne_pH = pH_Anfang+(-1)*math.log10(        (float(Anzahl_mol_von_HCl) - 
float(Anzahl_mol_von_NaOH))       /       ((float(v)*10**(-3)+float(g)*10**(-3)   )       )       
)       
print("Der PH-Wert beim Verhältnis von",v, "ml NaOH zu", g,"ml HCl ist gleich", berechne_pH)

Solution

  • I forgot to convert the pH to a float. Now it's clear.