Posts

17.Tic-Tac-Toe.py

  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 ...

16.HarRozNews.py

 # To Show the TOP 5 news headlines and their author's name import requests import json #to just fetch the news form the newsAPI websites as it is r = requests.get( 'https://newsapi.org/v2/top-headlines?country=in&apiKey=b0e1da350f2e46649f9865d403b8b9d3' ) # print(r.content) #to make it readable json is used news = json.loads(r.content) # print(news) #to print top TOP 5 news for i in range ( 0 , 5 ): print ( " \n " + "News" , i+ 1 , ":" , news[ 'articles' ][i][ 'title' ], " \n " , news[ 'articles' ][i][ 'description' ])

15.PyStopWatch.py

  # 1. import the Tkinter and ttkthemes modules # 2. We need a window with following elements: # -timer label # - button for starting/stopping # -button for resetting the timer to 0 # - function 'count' to update the timer display every second while running # -the time should displayed in the 'h:m:s' format import tkinter as tk from ttkthemes import ThemedStyle class Stopwatch(tk.Tk): def __init__ ( self ): super (). __init__ () self .title( "Py StopWatch" ) self .geometry( "500x190" ) self .time = 0 self .running = False self .style = ThemedStyle( self ) self .style.set_theme( "adapta" ) self .label = tk.Label( self , text = "00:00:00" , pady = 5 , padx = 5 , font =( "ds-digital" , 50 , 'bold' ), bg = "yellow" , fg = "green" , width = 20 , height = 1 ) self .label.pack() self .ala...

14.Clear The Clutter.py

# Write a problem to clear the clutter inside a folder on your computer. # You should use OS module to rename all the png images from 1.png all the # way till n.png where n is the number of png files in that folder. # Do the same for other file formats. # For example: # sdfs.png --> 1.png # sase.png --> 2.png # ljkli.png --> 3.png import os files = os.listdir( r"D:\PYTHON B TO A\png files" ) i = 1 for file in files: if file.endswith( ".png" ): print (file) os.rename( fr"D:\PYTHON B TO A\png files\ { file } " , fr"D:\PYTHON B TO A\png files\ { i } .png" )         i = i + 1  

13.Library Management SystemOOPs.py

# 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...

12.Gym Management System.py

# Health Management System # 3 clients - Harry, Merry, Jerry def getdate (): import datetime return datetime.datetime.now() # Total 6 files # write a function that when executed takes as input client name # [Time] chicken,roti # One more function to retrieve exercise or food for any client # ask user to lock or not # then ask for whom to lock: Harry/Merry/Jerry # what to lock Exercise or diet # Write a message that (f"File Written Successfully for {Name}") def take (k): if k == 1 : c = int ( input ( "Enter 1 for Exercise and 2 Diet" )) if c == 1 : value = input ( "Type here \n " ) with open ( "Harry_ex.txt" , "a" ) as op: op.write( str ([ str (getdate())]) + ": " + value + " \n " ) print ( "Successfully Written" ) elif c == 2 : value = input ( "Type here \n " ) with open ( "Harry_di...

11.Snake Water Gun Game.py

  # 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...