Placeholder Image

字幕表 動画を再生する

  • what is going on?

  • Everybody, welcome to part 11 of our Python three basics tutorial.

  • Siri's where we have been learning to build a game of tic tack toe to pretty much just learn the basics of python wall actually doing something of interest.

  • So, um so where we left off, we were determining the horizontal row of winners.

  • And now we want to just do the vertical row next, or vertical wind.

  • Basically, eso it really be calm.

  • Anyways, uh, let's go and get into it.

  • So what I'm gonna do is actually gonna comment out this section because I just all I want the only code I want right now is just for vertical Wind later will combine all of the wind types of codes ended the same function, but for simplicity, we're just going to do, come, do this.

  • So here we have a, uh, at least a game map.

  • It didn't look very fair for player number one, but we have a game app where player to clearly one vertically.

  • So how could we determine that player to has won or that somebody has one?

  • Well, um, basically would have to be everything in each row every everything with the same index.

  • Ah, would have to be the same number.

  • So, for example, for row in game, If we print ro zero and we run that, we can see it a rates overall, the rose prints the zero with, you know, So like, the first element in each row you see to to to write, and then you could have some sort of check here that's just gonna be like a list.

  • And because, remember, we have a little check calling or check functionality here that determines whether or not, uh, someone is one.

  • So we actually could use this exact same logic.

  • So it, in fact, I'm gonna copy X.

  • I'm about to use it on.

  • Let's upend rose zero to check.

  • So a list, unlike a to pull a list you can continue building, so add a value to the end of a list.

  • We can use a pen so you could say check dot upend.

  • And then we're gonna upend what?

  • We're gonna just depend the value that is rose zero.

  • So then I just wanted to comment that out.

  • Uh, then after we've done that, we could check, um, and we'll just have this over.

  • And instead of being row count, we're gonna do check.

  • So if check dot count, check zero and then check and then check.

  • Uh, and in fact, let me full screen this.

  • I don't know why it was so small.

  • Um, print winner.

  • So now if we run that, we get winner.

  • And then if we were to change this, hopefully back to one, we would see.

  • Okay, there's no winner.

  • Great.

  • So obviously, that's great.

  • But we've, you know, hard coded the check for rose zero.

  • So how could we go about checking all of them?

  • Well, of course we could do this.

  • You know, this little snippet here.

  • And by snippet, I mean, not a snippet and little actually all the way up to here and do it four times or three times rather for, uh, the zeroth index the first and the second if index.

  • Um, but obviously, as I've said before, that's really not ideal.

  • We want this code to remain dynamic is possible.

  • So, um and yes, I am aware that well, there's two major things.

  • One is the print of 012 at the top of our game map that we've worked on before is not dynamic.

  • We'll fix it.

  • Don't worry.

  • And the game itself is not really changeable.

  • Easily, but again, we'll fix it.

  • Don't worry.

  • Anyways, we want to keep it as dynamic as possible.

  • So what could we do?

  • Well, we could, um I think I'm gonna leave this here.

  • I guess Check can stay.

  • But basically, we would say, you know, we would need some number of columns and 01 in tubes.

  • 012 and then, um and then iterated, you know, four col in columns, Um, and then run this and then it would be row a call, and then the rest stays the same.

  • So again, run it, Winner.

  • Um, And then if we changed this and then we did I don't know like this now, player.

  • When I actually got an opportunity to play this time player 11 and we could comment this one out.

  • Okay.

  • No winner.

  • Cool.

  • So?

  • So this logic clearly eyes working.

  • But again, we've got this is being hard coated in, and we don't want that.

  • So what could we do?

  • Well, um, this is, you know, it's three elements, and it's just income It starts from zero in increments by one per each.

  • What?

  • Well per each column that we have.

  • And also the sense the game square you could say per row that we have as well.

  • So if we were to get, say, the Len, which is a built in function for Python Len of game Um, the answer to that is equal to three.

  • Also, we could just have a counter like you could literally four Cole And you could say for call, um, in column.

  • Uh, rather than that you could say for call in like, um, I'm trying to think of a really good, really good way to get around it.

  • But Kong's basically we could just say columns is, um, like if you just wanted to reiterate 012 What probably best way is with a range.

  • So again, range isn't something that we've talked about, but it's a built in function in python.

  • So mi do built python functions really built in python functions 3.7.

  • Maybe I'm surprised that wasn't like the top result.

  • I must type two different than normal anyway.

  • We come down to range and we can actually see that range.

  • Um, is it going to explain range?

  • Huh?

  • Anyway, OK, it does, rather than being a function range is actually an immutable sequence type.

  • So it's actually not a function, but we treat it like a function.

  • So it's okay.

  • We all just it's it's included in the built in functions because we treat it like one, but in the back, and it's actually not a functioning so much, it's much more efficient.

  • Um, the reason why you'd want that is, in theory, you could do, um, you know, range of like a huge number and that won't blow your memory.

  • But if you were to do something to convert it to a list, for example, and make that a list of that size that will absolutely blow your memory.

  • So let me open up the command window real quick.

  • Let's run pie dash Three points.

  • Not through 637 I'm so used to typing the 36 there.

  • Uh, okay.

  • And let's just say, um X equals range three.

  • And then, like four I in x a prince, I you get 012 Okay, so it just iterating over that, and it's not quite a list it's much more efficient than a list.

  • Um, and we'll see later that there's other operations that we can do on this that are similar operations to what we could do to a list.

  • A CZ.

  • Well, so anyways, that's how I think we should go about it where basically this number three is just the len of the game.

  • So what we'll do is we'll come over here.

  • And so for rather than being four, call in columns.

  • What will say is, four call in, um, and then we'll just do range, Len game, and then we can get rid of this silly columns.

  • Run it again.

  • Okay.

  • No winner.

  • Let's add a winner here.

  • Let's do this running.

  • Okay, We've got a winner, and then we can change that.

  • Go.

  • Maybe do this One over here.

  • Winner.

  • Cool.

  • Nobody should win.

  • Cool.

  • Nobody wants.

  • Okay, So, um, I think that, uh, the private next thing that we want to do is, um I think in the next video we'll do both.

  • Hopefully, we can do both of the diagonals.

  • I don't really think there's going to be.

  • I want to stuff that in this video.

  • Um, anyways, so This will be our methodology for detecting vertical winds.

  • Uh, and this should work, at least from the upset me to click on that.

  • This should work.

  • Um, for any size game board.

  • It's just going to run through all of the Rose at those specific indexes.

  • Um, and if there's a winner, cool, we print winner, and later we'll print winner to be a little more dynamic.

  • Say who won?

  • How did they win and all that?

  • So we will get to stuff like that.

  • But for now, I think I'll stop here.

  • And in the next tutorial, we are going to do the diagonals, which arguably is, um, maybe the hardest, but shouldn't be too bad.

  • So anyways, that's all For now, if you've got questions, comments, concerns, whatever, feel free to leave him below.

  • Otherwise I will see you in the next video.

what is going on?

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

A2 初級

Vertical Winners - Python 3 プログラミングチュートリアル p.11 (Vertical Winners - Python 3 Programming Tutorial p.11)

  • 0 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語