How to arrive at correct preconditions and postconditions?

I read about Hoare’s logic and algorithm correctness and how mathematicians prove an algorithm is correct,But I think how does one arrive at the required precondition and postcondition?(Inductive generalization).Please suggest further readings on discovering preconditions and postconditions(theorems),I heard about computational thinking and problem solving ,does reading these topics will help regarding this point?