当前位置:网站首页>I've seen many tutorials, but I still can't write a program well. How can I break it?

I've seen many tutorials, but I still can't write a program well. How can I break it?

2022-07-06 20:19:00 Crossin's programming classroom

Zero basis python Introductory tutorial :python666.cn

Hello everyone , Welcome to Crossin Programming classroom of !

Recently, in the communication with students , It is found that many beginners are faced with such a problem : Learned some basic grammar , I can understand the examples in the book , But when it comes to a new programming problem , Still feel unable to start . The reason is , There are mainly two aspects :

  1. On the whole , I don't know how to translate the problem into programming language .

  2. In detail , I don't know how to realize a function .

For example, there is a problem in our code action programming example , The main idea is : Generate 200 A discount code , Each coupon code is provided by 8 It's made up of two letters ( Include case ).

Of course, the topic itself is not very difficult , And our official account 【 Every Monday 】 Compare the questions in the column , This is small case 了 . But if you're a new programmer , Only then can we master the condition judgment 、 loop 、 For beginners of the list , It's still a little bit of a challenge .

In this case , Some people have no idea of generating a string of characters directly , I don't know what to do . More people may have some ideas , But in the specific link , For example, how to generate random letters 、 How to spell a string 、 If you have trouble judging repetition . It can be seen from the participants' comments that , Many people exclaimed : It turns out that there is xxx This function 、 also yyy This module , I don't know at all .

So when developing programs , How to solve similar problems , And find the right way ? I'd like to share a few experiences :

1. Learn to break down problems

There's a joke about mathematicians being firefighters :

The fire chief asked : If a warehouse in the alley is on fire, how ? A mathematician : Connect the fire hydrant to the hose , Turn on the tap , Put out the fire . The captain said : Absolutely right ! What if you come to the alley and find that the warehouse is not on fire ? A mathematician : Light up the warehouse , So the problem is reduced to a known problem .

Put aside the exaggeration of the joke itself , As a programmer , You need to have a similar logic : Decomposition and transformation problems .

  • Generate 200 A discount code => Generate 1 A discount code , loop 200 Time

  • Generate 1 individual 8 Bit discount code => Generate 1 Characters , loop 8 Time

  • Generate 1 Random characters => Generate a random number , Convert to character

Generate a random number , It's a question we've been asking for a long time , use random Modules can be implemented . Then the thinking of this problem is quite clear . The rest is to deal with the details of the process : If you convert from numbers to characters 、 How to cycle 、 How to splice and so on .

But surely some students will say , I didn't even know numbers could be converted into characters . Some students will also say , You don't have to go around this bend at all , It can generate random characters directly . you 're right , Just like the mathematician who lit the warehouse , We have no problem with this logic , But in fact, it seems that there are still some two . So another important experience :

2. Learn to use search

Although most programmers major in Computer Science in College (science), But the role in the enterprise is Engineer (engineer). in other words , Programming is more practical than theoretical . Our goal is to solve the problem , What we need to master is the means and methods to solve the problem . For programmers , Search is a very effective way to find a solution .

But many students who have no programming experience may think that , When learning programming, finding a solution by searching is a kind of “ cheat ” The way , I didn't really understand how to solve the problem . There's no need for that . Even experienced programmers , And before we deal with it , Search for a more suitable solution . It's more valuable for you to search for solutions than to write this little program . I once wrote an article here , About how to use search engines : Programming beginners how to use search engines .

As far as the discount code is concerned , Through some simple search , We can find many similar solutions . Of course you can't search “ How to make 8 Bit discount code ”, But search “Python Generate random string ” Such keywords . Then you know : It can be used random Of sample、shuffle, And then there is string This module can utilize .

By the way . A classmate once asked : Does your tutorial include the knowledge needed for job hunting . This is a similar mistake . We are not going to take the college entrance examination , Review according to the outline , Then go to the examination room . Today's computer industry can be said to update faster than any industry , You can never “ Completely ” After mastering the knowledge of a certain field, develop it , You need to constantly face new technologies and new problems . So the knowledge about programming is changing , What we need to master is the same solution .

feb44b9b105cef71e3905fc497dbca77.png

And for any field , The distribution of knowledge is like this picture , As you go further , The more knowledge gaps you face . This is also why many students after learning the basics , I can't find a suitable textbook to advance . Because there is no such textbook at all . In the primary stage , The pattern of your ability enhancement is Learning skills -> Practice your skills , And to a certain extent , The way to improve ability must be Have a problem -> Find a way to solve the problem , It's a process from passive to active . therefore , Students who want to go further , Don't look for textbooks , It's looking for problems , Use it again “ Search for ” This great tool to solve it .

The same is true of our teaching methods : We're not giving you textbooks , All the resources on the Internet should be your teaching materials . We'll give you a question , And how to find a solution to the problem .

3. Learn to look up documents

There is such a word in the programmer class :RTFM(Read The Fuxxing Manual, To read TMD Documentation manual )

There's a similar one STFW(Search The Fuxxing Web), It is corresponding to the first 2 spot .

I once a teacher pointed to a thick programming textbook and said to us : You don't have to remember these functions at all , It's enough to know where to look when you use it .

Search can tell you what solutions are available , And the official documents tell you more clearly how to use , What are the limitations of the parameters , Things to pay attention to and so on . The only regret is that , majority Fuxxing Manual It's all written in English . So you said , English is not good, in the end can learn programming . I can only say , Sure , But I strongly suggest you make up for your English .( The good news is that more and more documents are now available in Chinese )

Let's go back to the topic , adopt Python Official documents , You will know random What random operations can the module do , as well as string What strings can a module generate .

Last , And a little bit of platitude :

4. Keep practicing , Accumulate experience

I've said it countless times : Programming is like musical instruments , Learning grammar is just the beginning , It takes practice to master . Every programmer is a stack of lines of code . If you're new to programming , I feel like I lack programming thinking , I often sigh that there is still such operation , Write a little bit longer and you'll get old bug Words , believe me , You just write too little , Too little . Don't belittle yourself , There's no need to rush for success , Practice more first . After you input and run the sample code of a tutorial on your computer , Let's talk about programming thinking . This is not my original wonderful teaching method , Most programmers and computer teachers should agree with this .

The above is a little experience as a past person , I hope it can help people in need .

thank forward and give the thumbs-up The fellow ~


_ Previous articles are recommended _

And want to learn Python Students who have changed careers have a chat


If you need to know Paid premium courses And Teaching Q & a service

Please be there. Crossin Programming classroom of Internal reply : 666

0bdafdfab6dd33b6d574e49f94ba0026.png

原网站

版权声明
本文为[Crossin's programming classroom]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207061223232791.html