Since you didn't format your code, it's not clear if it is indented correctly.
In any case, this looks incorrect:
Code:
cur.execute("select firstclass_amount from train_details where id==?"
(id1,))
Shouldn't there be a comma after the string?
Same for a few lines further down.
By the way, your question has nothing to do with Linux.