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...
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...
Python pls Create a function party_freq(dicto:dict): this function returns a list inside tuple that how many...
Python pls Create a function party_freq(dicto:dict): this function returns a list inside tuple that how many times each person party in the day. For example def party_freq(dicto:dict) -> [(str,{(int,int,int): int})]: #code here input dict1 ={'fire1': {(2000,5,20,480) : ('Aaron', 25, 300, ( 0, 300)), (2000,5,20,720) : ('Baily', 45, 1500, (1500,500)), (2000,5,21,490) : ('Aaron', 35, 500, (1300,500)) }, 'fire2': {(2000,5,20,810) : ('Baily', 45, 1400, (600,1600)), (2000,5,20,930) : ('Baily', 43, 1800, ( 0, 0)) }} output [('Aaron', {(2000,5,20): 1, (2000,5,21): 1}), ('Baily', {(2000,5,20):...
Python This part involves creating a function that will manage a List of unique strings. The...
Python This part involves creating a function that will manage a List of unique strings. The function is passed a string and a list as arguments. It passes a list back. The function to add a word to a List if word does not exist in the List. If the word does exist in the List, the function does nothing. Create a test program that takes a string as input and then calls the function over and over until the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT