Today I completed the content for week three, which included many commands, especially various string manipulations such as slicing, splitting, and formatting. Among them, creating a progress bar needs to be run in cmd, and I haven’t found a feasible method yet.In today’s exercises, I encountered a problem related to the Caesar cipher. This seemed familiar because I also encountered it during my studies in C and C++.
After spending half a day writing the program, I reviewed the answers, and my memory suddenly returned to the classroom from a few years ago:
My answer was based on very obvious underlying logic:
From start to finish, the process of searching, replacing, and concatenating was done without realizing that letters already have their own order in the computer. The index function I learned a few days ago was very useful.So many times, I write programs using C language and Python logic, which is also reflected in the problem below:
I started with locating, slicing, and looping again. Unfortunately, I was using C thinking, so the code threw an error. I remember using this kind of loop often in previous classes.
As a result, Python provides many string manipulation methods, including a split function that can divide a string into an array based on specified elements. So in reality, the final program only had three lines:
Therefore, one should make good use of the various useful commands provided in Python, and many problems can be solved without resorting to low-level thinking.——————————-I continued debugging Teacher D’s erroneous program. I don’t know how Teacher D wrote it, but there are undefined variables everywhere, which has made the original flavor disappear after many modifications. So I will first post the question and continue writing this problem later.