Posts

Showing posts from May, 2023

Working with OS module in Python

import os def soldier(a,b,c): os.chdir(a) i = 1 items = os.listdir(a) for item in items: if item.endswith(b): os.rename(item, item.capitalize()) if item.endswith(c): os.rename(item, f"{i}.{c}") i += 1 fpath = r"D:\abdur codes\space\thisisit\fffffffffffffffff" filename = ".py" format = ".png" soldier(fpath, filename, format) ###################################################################### import os def soldier(fpath, filename, format): os.chdir(fpath) i = 1 files = os.listdir(fpath) with open(filename) as f: # this file contains files names which we will not tamper with filelist = f.read().split("\n") for file in files: if file not in filelist: os.rename(file, file.capitalize()) # if os.splitext(fpath)[1]==format: if os.path.splitext(fil

Command Line Utility of a Faulty Calculator

import argparse import sys def calc(args): if args.o == "+": if (args.a == 56 and args.b == 9) or (args.a == 9 and args.b == 56): return 77.0 else: return args.a + args.b elif args.o == "-": return args.a - args.b elif args.o == "*": if (args.a == 45 and args.b == 3) or (args.a == 3 and args.b == 45): return 555.0 else: return args.a * args.b elif args.o == "/": if args.a == 56 and args.b == 6: return 4.0 else: return args.a / args.b else: return "Something went wrong. Try again!" parser = argparse.ArgumentParser() parser.add_argument("--a", type=float, default=1, help="Enter your first number plz") parser.add_argument("--b", type=float, default=0, help="Enter your second number plz") parser.add_argument("--o", type=str, defaul

Python Puzzle Game

This code implements a simple puzzle game using the Pygame library. It loads a background image and puzzle piece images, creates a 3x3 grid of puzzle pieces, and allows the player to click and drag pieces to swap them. The game checks if the puzzle is solved after each move, and displays a congratulatory message if the puzzle is solved. Here's a brief summary of the code: The Pygame library is imported and initialized. The game window is set up with a width of 483 pixels and a height of 480 pixels, and a caption of "Make Abdur - Puzzle Game". The background music and sound effects are loaded from sound files. The puzzle piece images are loaded from files and stored in a list called pieces. The game loop starts, which repeatedly draws the background image and puzzle pieces on the screen and waits for user input. User input is handled using Pygame's event handling system. Specifically, the game listens for QUIT, MOUSEBUTTONDOWN, MOUSEBUTTONUP, and MOUSEMOTION events. Wh