In today’s educational environment, with the popularization of laws, more and more students pay attention to the maintenance of their own rights. However, due to the misinterpretation of punishment, it is very easy to mistake teacher punishment for “corporal punishment.” Therefore, it is particularly important to investigate the impact of teacher discipline on students. This paper first collects some knowledge related to the research based on the research results of scholars, and then makes a detailed analysis of this research from two aspects. It, respectively, introduces the influence of teacher discipline on teaching effect and students’ psychology in universities, and the normative suggestions for discipline behavior in this paper. It then uses formulas to explain how the teaching and learning optimization algorithm works. Finally, it analyzes the changes among teachers’ discipline, students’ psychology, and coping style through experiments. The results showed that urban students had the highest probability of being disciplined for being late, at 53%, and the lowest probability of being disciplined for not completing homework, at 34%.