Connect 4 Program Python In Windows
Hello This is like my 4th week using Python and I'm still not familiar with it so I might need some help from you guys. I gotta write a little Connect 4 game in Python, I just got started and boom - I'm stuck!
I tried to create a board for the game using two lists. Here is how far I got: def board(): fielda = [] fieldb = [] rows = int(raw_input('Height ')) columns = int(raw_input('Width ')) if rows. Wow, that was fast, thanks. It works perfectly but umm. What does your code actually do?
I don't get through it - any comments maybe? Well best way to understand it is to hand-execute it:) for row in fielda: for spot in row: print spot, print so, the first row in fielda is row = [ '-', '-', '-', '-', '-' ] going in the second loop: the first spot in it is '-', therefore it prints '-' and remains on the same line because of the ','( comma ) after the print statement. Harry Potter And The Chamber Of Secrets Nl Subs. So if loops over every '-' in the row and prints it.
When it gets to the point that no more elements are left, exits the loop and uses 'print' to go to the next line of the output. Since there are no other statements in the body of the outer for loop, it continues to the second row and so on. Hope this makes it clearer:) Edited 8 Years Ago by masterofpuppets: messed up the tabs. I'm sorry, I didn't comment it because I saw you use some of the code in your project and just assumed things, but here's what it does. Contemporary Intellectual Assessment Pdf File. Whenever you have for obj in container:, python does the for loop once for each obj that's in container. SomeList = [1,2,3] for i in range(3): print someList[i].is the same as.
SomeList = [1,2,3] for num in someList: print num When I did for row in fielda:, that did the for loop once for each list inside the list fielda, and referred to that inner list as row. When I did for spot in field:, that did the for loop once for each character inside the list row, and referred to that character as spot. Notice my names are intuitive. Row refers to a row on your board, and spot refers to a spot on your board. Print spot, prints out the character spot, then doesn't end the line because of the comma. Print on the next line makes sure to start a new line for each new row.
Connect-Four - Connect Four game. Connect Four game written in python 39. When the game is initialized, the program asks. Limit my search to r/learnprogramming. And well-formatted program that illustrates your problem. Connect Four in Python.