import tkinter as tk from tkinter import messagebox # Initialize current player as "X" and set winner flag to False current_player = "X" winner = False # Function to check for a winner def who_wins (): global winner # List of winning combinations for combo in [[ 0 , 1 , 2 ], [ 3 , 4 , 5 ], [ 6 , 7 , 8 ], [ 0 , 3 , 6 ], [ 1 , 4 , 7 ], [ 2 , 5 , 8 ], [ 0 , 4 , 8 ], [ 2 , 4 , 6 ]]: # Check if the buttons in the current combination have the same text and are not empty if buttons[combo[ 0 ]][ "text" ] == buttons[combo[ 1 ]][ "text" ] == buttons[combo[ 2 ]][ "text" ] != " " : # Highlight the winning combination with a green background buttons[combo[ 0 ]].config( bg = "green" ) buttons[combo[ 1 ]].config( bg = "green" ) buttons[combo[ 2 ]].config( bg = "green" ) # Show a message box declaring the winner ...
# Snake Water Gun #Snake,Water and Gun is a variation of the children's game "Rock-Paper-Scissors" # where players use hand gestures to represent a snake, water, or a gun. # The gun beats the snake, the water beats the gun, and the snake beats the water. # Write a python program to create a Snake Water Gun game in Python using if-else statements. # Don't create any fancy GUI. Use proper functions to check for win. # S W G # Computer = 0 1 2 # Player = S 0 D W L # W 1 L D W # G 2 W L D import random def check (comp,user): if comp == user: return 0 if comp == 2 and user == 0 : return - 1 if comp == 1 and user == 2 : return - 1 if comp == 0 and user == 1 : return - 1 else : return 1 comp =random.randint( 0 , 2 ) # print(comp) user = int ( input ( "0 for Snake, 1 for Water, 2 for Gun: \n " )) print ( "You:" ,user) print ( "C...
# Write a "Library" class with no_of_books(int) and books(list) as two instance variables. # Make a method that checks whether the no_of_books== books(len) # Write a program to create a library from Library class and show how you can print all books, add a book and get the number of books using different methods. # Show that your program dosent persist the books after the program is stopped class Library: def __init__ ( self , no_of_books, books): self .no_of_books = no_of_books self .books = books def check ( self ): # Check whether the number of books matches the length of the books list if self .no_of_books == len ( self .books): print ( "Number of books matches the length of the books list." ) else : print ( "Number of books does not match the length of the books list." ) def print_all_books ( self ): # Print all books in the library print ( "Books in the l...
Comments
Post a Comment