دوره Programming for Everybody (Getting Started with Python) ، فصل 7 : Chapter Five- Loops and Iteration

درباره‌ی این فصل:

Loops and iteration complete our four basic programming patterns. Loops are the way we tell Python to do something over and over. Loops are the way we build programs that stay with a problem until the problem is solved.

این دوره شامل 7 فصل زیر است:

So, an important part of any loop is what we call the iteration variable, okay? And what we do is if we find a line like this one that has pound sign as the first character, we skip back to the beginning of the loop. I constructed it, so that it would eventually either exit the loop or the condition would become false.

So up to now we've been talking about indefinite loops, and that's the use of the while keyword that just runs until some logical condition is false or you hit a break. So you know that this code is going to run three times, and friend is going to take on Joseph, Glenn, and Sally in successive iterations through the loop. So, like I said, definite loops are for lists or lines in a file or characters in a string, and, you know, they iterate through members of a set.

And so we're going to construct loops sort of with an idea of doing something to each value in the set that we're iterating through. And so we have to realize, the purpose of that last little exercise, was to think when we construct loops how computers are going to attack this kind of a problem. So up next we're going to talk about more of these loop idioms and how to find the smallest, and how to count things, and how to do averages and sums and stuff like that.

So this is kind of a filtering pattern where we are going to do some if statement and conditionally run some code based on the value that we are looking at for now. We have yet another type of variable, remember I had boolean, True and False, integer, floating point. To use this None and then have a little bit of code that triggers the first time through the loop to get your sort of loop-carried variable setup.

I'll say print Five and I'm going to do this because now I need to get to the point where I'm in the same folder in this terminal window, cd Desktop/py4e/ex, I can string these together. Now we need to write a loop, and I'm going to write this as an infinite loop, while True, with colon, and then I'll indent, and I'll prompt for a string, and remember input gives us a string, so I'm going to call this sval = input. That's what we are going to get and that roughly achieves this same thing and it's a combination of a loop with a exit mechanism.

We also, because we had to have some kind of graceful exit from my previous employer, who claimed a certain amount of ownership over the source code. And sort of over the summer and the fall of 2000, this startup company began to show more and more signs of dysfunction. I mean, at the last PyCon conference, I had to, sort of, hold off a whole bunch of people with very good arguments of why we should do a Python 2.8 release.

We are here in Paris France with yet another face to face office hours for Coursera, and I'd like you to meet some of your fellow students. In a bit I will hop on a plane and go to Milan. This is called the fashion tour of Paris and Milan, except that I don't have the clothes for that.

مشارکت کنندگان در این صفحه

تا کنون فردی در بازسازی این صفحه مشارکت نداشته است.

🖊 شما نیز می‌توانید برای مشارکت در ترجمه‌ی این صفحه یا اصلاح متن انگلیسی، به این لینک مراجعه بفرمایید.