Posts

Showing posts from November, 2020

HangMan game in PYTHON

Image
  What is hangman? Libraries Hangman  is a paper and pencil guessing game  for two or more players. One player thinks of a word, phrase or sentence  and the other(s) tries to guess it by suggesting  l etters  within a certain number of guesses.  wikipedia Code: import random as r listOfWords1 = ["pace", "space", "cross", "edge", "nine", "tame", "spawn", "real", "world", "seed"] listOfWords2 = ["computer", "physics", "science", "sapiens", "building"] def main():     guesses = ""     level = input("Easy(e)/Medium(m)/Hard(h):\n").lower()     print("----------")     if level == "e":         turns = 5         word = r.choice(listOfWords1)     elif level == "m":         turns = 3         word = r.choice(listOfWords1)     elif level == "h":         turns = 3         word = r.choice(list

Tic-Tac-Toe (multiplayer) using pthon

Image
  About The Game:   Tic-Tac-Toe (also known as noughts and crosses) is a paper and pencil game for two players, X and O , who take turns marking the spaces in a 3×3 grid. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row is the winner. It is a solved game with a forced draw assuming best play from both players. wikipedia Tic-Tac-Toe in python: def printBoard ( currentPos ): print ( " {} {} {} " .format(currentPos[ 0 ], currentPos[ 1 ], currentPos[ 2 ])) print ( " {} {} {} " .format(currentPos[ 3 ], currentPos[ 4 ], currentPos[ 5 ])) print ( " {} {} {} " .format(currentPos[ 6 ], currentPos[ 7 ], currentPos[ 8 ])) def askPos (): global pos pos = int ( input ( "row (0 to 2): \n " )) if pos < 0 or pos > 8 : print ( f " { pos } is an invalid row number!" ) askPos() def updatePositions ( position , playerSymbol ): position[pos

opening sites with PYTHON

Image
"webbrowser" is a module in python which allows to display web-based documents to users. Instal lation: "pip install webbrowser" Functions: Here are some of the functions of webbrowser module: * webbrowser.open(url) - to open the given url * webbrowser.open_new(url) - to open the given url in a new window * webbrowser.open_new_tab(url) - to open the given url in a new tab * webbrowser.get(browserName) - to open the given url in a specific browser(chrome, Firefox, etc) 1.webbrowser.open(url) This function is used to open the given url in any browser. Syntax : 1. import webbrowser 2. webbrowser.open(" https://pyiseasy.blogspot.com ") 2.webbrowser.open_new(url) This function is used to open the given url in a new window. Syntax : 1. import webbrowser 2. webbrowser.open_new(" https://pyiseasy.blogspot.com ") 3.webbrowser.open_new_tab(url) This function is used to open the given url in a new window. Syntax : 1. import webbrowser 2. webbro

Shorten your URL in 3 lines using PYTHON

Image
 * About The Library : "pyshorteners" is a Python library to help you short and expand urls using the most famous URL Shorteners availables. * Simple Code : 1. import pyshorteners 2. s = pyshorteners . Shortener () 3. print ( s . tinyurl . short ( "pyiseasy.blogspot.com" ))

Simple Calculator (Tkinter)

Image
  Required libraries:   tkinter ( pip install tkinter ) Explanation:   modules imported:-     1. from tkinter import * - importing every function from tkinter library     2.messagebox - to show any popup message calculator class:-     1.making basic tkinter window and giving required details(background colours, geometry, etc.)     2.frame 1 (titleFrame) :- the first frame only contains title ("gCalc") of the calculator     3.frame 2 (workFrame) :- it have all the main stuff          i. entryPlace : entry widget to write the equation          ii. "=" button : button to evaluate the equation entered in the entryPlace and then print answer on it     4. calculate function :-          i. try and except : NameError exception is handled(if user will enter an invalid equation, it will show error in a popup window titled "typo?")                      ii. "eval()" function is used to evaluate any valid equation given in the entryPlace Code :  from tkint