Question

In: Computer Science

Creating a list/tuple in python 2. Using a list of lists containing X’s and O’s to...

Creating a list/tuple in python
2. Using a list of lists containing X’s and O’s to represent a tic tac toe board, write code to check if the board has a winner.

Solutions

Expert Solution

Program Code Screenshot :

Sample Output :

Program Code to Copy

def hasWinner(board):
for i in range(len(board)):
winner = True
for j in range(1,len(board[i])):
if not (board[i][j] is board[i][0] and board[i][j] in ('X','O')):
winner = False
break
if winner:
return True

for j in range(len(board[0])):
winner = True
for i in range(1,len(board)):
if not (board[i][j] is board[0][j] and board[i][j] in ('X','O')):
winner = False
break
if winner:
return True

winner = True
for i in range(len(board)):
if not (board[i][i] is board[0][0] and board[i][i] in ('X','O')):
winner = False
break
if winner:
return True
winner = True
for i in range(len(board)):
if not (board[i][len(board)-i-1] is board[0][len(board)-i-1] and board[i][len(board)-i-1] in ('X','O')):
winner = False
break
return winner


Related Solutions

Creating a list/tuple 3.Given a list of tuples containing student first names and last names e.g....
Creating a list/tuple 3.Given a list of tuples containing student first names and last names e.g. (“John”, “Doe”) that represents a class. Ask the user for a students first and last name and check if that student is a member of the class.
Python Question Using lists, write the function non_unique(list) that takes a list list as argument. It...
Python Question Using lists, write the function non_unique(list) that takes a list list as argument. It returns a list which duplicated elements remains and each duplicated element is followed by a number which shows how many times it appears. All elements in return list should be in the same order as their appearance in the original list. For example, given the input [‘a’, ‘b’, ‘c’, ‘a’, ‘b’, ‘d’, ‘a’,‘e’], the function would return [‘a’, 3, ‘b’, 2]. Another example, ['abc',...
Creating a list/tuple 4. Write a program to accept a string from the user, then replace...
Creating a list/tuple 4. Write a program to accept a string from the user, then replace the first letter with the last letter, the last letter with the middle letter and the middle letter with the first letter. E.g. “Billy” -> “yiBll”.
C++ Linked Lists Practice your understanding of linked lists in C++ by creating a list of...
C++ Linked Lists Practice your understanding of linked lists in C++ by creating a list of songs/artist pairs. Allow your user to add song / artist pairs to the list, remove songs (and associated artist) from the list and be sure to also write a function to print the list! Have fun! Make sure you show your implementation of the use of vectors in this lab (You can use them too ) You MUST modularize your code ( meaning, there...
Use Python to Load a file containing a list of words as a python list :param...
Use Python to Load a file containing a list of words as a python list :param str filename: path/name to file to load :rtype: list
C++ coding functions Implement the following class using linked lists. Creating a simple linked list class...
C++ coding functions Implement the following class using linked lists. Creating a simple linked list class to use is probably your first step.(Please do not use collections like .push() . pop(), etc.) and instead create the implementation A templated stack class that stores type T with the following public functions: - void Push(T t) - adds t to the top of the stack - T Pop() - asserts that the stack is not empty then removes and returns the item...
python find min in the tuple of dictionaries by date also how to sort this tuple...
python find min in the tuple of dictionaries by date also how to sort this tuple by effectiveDate Requests = ( { "Id": 1, "itemId": 2, "amount": 50, "effectiveDate": "11/15/2015"}, { "Id": 2, "itemId": 1, "amount": 200, "effectiveDate": "11/20/2015"}, { "Id": 3, "itemId": 3, "amount": 5000, "effectiveDate": "10/5/2015"}, { "Id": 4, "itemId": 3, "amount": 600, "effectiveDate": "10/6/2015"} )
Scrambled Word Game (Python) Topics: List, tuple In this lab, you will write a scrambled word...
Scrambled Word Game (Python) Topics: List, tuple In this lab, you will write a scrambled word game. The game starts by loading a file containing scrambled word-answer pair separated. Sample of the file content is shown below. Once the pairs are loaded, it randomly pick a scrambled word and have the player guess it. The number of guesses is unlimited. When the user guess the correct answer, it asks the user if he/she wants another scrambled word. bta:bat gstoh:ghost entsrom:monster...
How to do this in Python (using Lists): Create a python program that allows a user...
How to do this in Python (using Lists): Create a python program that allows a user to display, sort and update as needed a List of U.S States containing the State Capital and State Bird. You will need to embed the State data into your Python code. The user interface will allow the user to perform the following functions: 1. Display all U.S. States in Alphabetical order along with Capital and Bird 2. Search for a specific state and display...
Python: I am currently a function that will return a list of lists, with the frequency...
Python: I am currently a function that will return a list of lists, with the frequency and the zip code. However, I am having a difficult time organizing the list in decreasing order of frequency. We are asked to use sort () and sorted () instead of lambda. The function will find 5 digit zip codes, and when it sees a 9-digit zip code, the function needs to truncate the last 4 digits. The following is an example of the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT