chemistry and python

This is the place for queries that don't fit in any of the other categories.

chemistry and python

Postby fredjo » Tue Oct 22, 2013 6:46 pm

Hi!
I don't have much experience in python coding, and i wondered if anyone on this forum could help me out with this problem.

i need a function p(H) for calculation of pH; y = p(H) =-log (H).
The function can also be used for pOH, pKa, etc.
Use the function in a program that asks for the Ka-value for an acid, and then calculates
pKa, pKb for the corresponding base, and pH and pOH of a 1 M solution of acid and a
buffer consisting of acid and base in equal amounts.

Would be nice to keep the code as simple and short as possible.
Thanks :D
Last edited by stranac on Tue Oct 22, 2013 7:03 pm, edited 1 time in total.
Reason: First post lock.
fredjo
 
Posts: 3
Joined: Tue Oct 22, 2013 6:29 pm

Re: chemistry and python

Postby stranac » Tue Oct 22, 2013 7:05 pm

I think you misunderstood something.
This is a python help forum, not a place you get your homework written.

So you'll need to post some code if you want help.
Also, I think you'll find most of us have no knowledge of what those chemistry things mean(I know I don't).
Last edited by stranac on Tue Oct 22, 2013 7:36 pm, edited 1 time in total.
Reason: removed the random "no knowledge"
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1115
Joined: Thu Feb 07, 2013 3:42 pm

Re: chemistry and python

Postby fredjo » Tue Oct 22, 2013 7:33 pm

Very understandable. This isn't homework though, just a little something to make my own calculations quicker.

I'll try harder to figure it out myself then, and come back later.:) Then i'll post the equations needed for the calculations. They are very simple.
fredjo
 
Posts: 3
Joined: Tue Oct 22, 2013 6:29 pm

Re: chemistry and python

Postby stranac » Tue Oct 22, 2013 7:39 pm

Sounds like a plan.
If you get stuck, ask specific questions on things that you don't understand.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1115
Joined: Thu Feb 07, 2013 3:42 pm

Re: chemistry and python

Postby fredjo » Tue Oct 22, 2013 8:20 pm

So I need to calculate the negative common logarithm of the squareroot of a number defined as "Ka". This is what i got so far.

import math
Ka = input("please enter Ka here: ")
pH = -math.log(math.sqrt(Ka))
(This is where my first problem appears. i need the common negative log, not ln)

As i said, i don't realy have any experience in this :lol:
fredjo
 
Posts: 3
Joined: Tue Oct 22, 2013 6:29 pm

Re: chemistry and python

Postby stranac » Tue Oct 22, 2013 8:28 pm

Code tags, please.

The docs can be very helpful when you don't know how to use a function.
help(math.log) would also help(try it in the interpreter).
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1115
Joined: Thu Feb 07, 2013 3:42 pm

Re: chemistry and python

Postby ochichinyezaboombwa » Tue Oct 22, 2013 9:48 pm

math.log, if base is not specified, returns the natural logarithm.
ochichinyezaboombwa
 
Posts: 200
Joined: Tue Jun 04, 2013 7:53 pm


Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot] and 4 guests