Vertical Winners - Python 3 Programming Tutorial p.11

preview_player
Показать описание
Welcome to part 11 of our Python 3 basics series, in this part we're going to continue working on validating the winners of TicTacToe, specifically on vertical wins.

#python #programming #tutorial
Рекомендации по теме
Комментарии
Автор

You're going to make me cry, I've learned so much from your tutorials. I was afraid I was going to be a failure in life. I've been learning python for 2 years. You've help me land a job in python automation, no college degree, 5 time felon. I've changed my life around and I owe it to people like you, teaching the poor for free, for the love of coding. My first paycheck I will donate half of it to you. I don't know how I can thank you for giving me a skill for life. Truly grateful, I'm in tears as I write this. (excuse me grammatical errors)

RByrdsong
Автор

def win(current_game):
game_tr =list(map(list, zip(*game)))
for row in game_tr:
if row.count(row[0]) == len(row) and row[0] !=0:
print("Winner!")
break
for row in game:
print(row)


This was my try for this. As new i did a research at on built in fun ans this is what i made.I think it works fine and its easy since i just transpose the matrix

dslsezf
Автор

Respected sentdex,
I just want to let you know that your videos are so good! I am learning so much from them.
Thank You and All The Best for your channel!
Loads of Gratitude

ayushagarwal
Автор

I'm really trying to understand every bit of code to force myself to learn the applications of functions, loops, etc. The thing that helped me with this one was identifying that after:

for row in game:
check.append(row[col])
#print(check)
you can print(check) to see how check[ ] has been appended and thus you can see how it is that col, [1][2][3] - from range(len(game)) - works as idex identifiers for the 'row' value in the for loop - from (row[col]), thus indentifying the first index from each row value (or, row), then they are passed through the check.count code. If you run print(check) you can actually see the process the code is running to check those values and being able to see that and how each bit affected the other bits REALLY helped me. Happy programming!

wendbnew
Автор

This stuff clicking into place is so gratifying. Thanks for doing what you do. I'll help out when I can here in the near future.

DH-ggpg
Автор

Do you use different cups intentionally? :)

arusyakmelkonyan
Автор

You could also transpose the matrix by using "game1 = zip(*game)" and then run the same code as that of the horizontal win.

aintpunk
Автор

I didn't really get this one. Is there something else I should look at to be able to understand this part? Thanks :)

LaxyaPahuja
Автор

What are you drinking in those fancy mugs? ;D
Are you planning to make another Python 3 Programming Tutorials Course/Playlist for Intermediate level?

Greetings

RipYaZa
Автор

You have forgotten to add a check if the winner is not 0

neromagistr
Автор

Isn't len(game[0]) more correct? Now you counting rows.

kyufghbvtrgh
Автор

Iss such a simple game but literally eating away my brains

woahart
Автор

A little more advance. But with numpy we can just transpose the matrix and do check =

tomasmanrique
Автор

I did not try it out but... what about checking the colums as you did with the rows but using the Transpose of the game Matrix?

t_game = zip(*game)

AIMatesanz
Автор

I thought in transpose the matrix and use the same horizontal function, that could be donde with range or using the numpy library.

jandresshade
Автор

Hi,

Great Video. I am able to follow through most of it. One basic questions- can you explain more on what the below does only

check = []
for row in game:
check.append(row[0])

What are we doing here and then

check.count(check[0]) ---> has check got a value now instead of row[0]

confused! your help is greatly appreciated!
Thanks

sandeepsingh-mouc
Автор

I was thinking I'd nest the verticle check within a while loop
i = 0
while i < len(game):
<vertical check code here>
<your horizontal check code here>
i+= 1

Obviously you'd include the check for zero. But wouldn't this be an ideal situation to use a while loop (packaging the two checks together in a nice little nested bundle)?
I'm really new to programming so I'm sure you have good reason for not opting to go that way, but I'd appreciate it if you could tell me why. Also, I hope my pseudo code example makes sense.

As always, thanks A TON for your golden channel and the work that you do.

lank_asif
Автор

Woah woah, okay I get why you wanted to use range so we can understand what range is.
Also, an issue with your code is that you are doing `for col in range(len(game))` this will check the length of all ROWs, not columns. If you have a boomer boss he might want to make a tick-tack-toe with a board of 3x6 for example. In that case your code will iterate over 6 (the number of rows) instead of the 3 columns !!!!
Simple solution, we assume that if the first row has 3 columns, then every other row has 3 columns. If your boss is so insane to make a tick-tack-toe game with rows that have different number of cols then you might as well present him with your 2 weeks notice... so back on track, all you have to do is check the len of the first row, which is len(game[0]) which will return 3 in our 3x6 case.

denislavkaragiozov
Автор

I have a question, but not python related. How many wired giant mug do you have? I can't recall any mug, which I've seen twice.

abdullahalmubin
Автор

Thank you for the time and effort that goes into making these videos. I have a question; is it normal when watching a few of these in a row you suddenly have a hard time following it? I got lost at the check.append part (around 3 minutes).


Edit: I came back to it 10 mins later, checked your next video and it suddenly clicked together. Great feeling! For some reason it didn't sink in that with check [] you were making a new list. I guess watching all 11 in a row requires as many coffees as you have mugs for me.

MrTimdeK