Advertisement
SigmaBoy456

python ggg/re project #385

Mar 6th, 2025
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.32 KB | None | 0 0
  1. import re
  2. import pyfiglet as pyfl
  3. import matplotlib as mt
  4. import matplotlib.pyplot as plt
  5. import numpy as np
  6. from random import randint
  7. from random import choice
  8. import sys
  9. import os
  10. import time
  11. #GeekForGeek Project (In Progress)
  12. class GeekForGeekProject:
  13.     def __init__(self):
  14.         self.textart = pyfl.Figlet()
  15.         self.textart.width = 150
  16.     def GuessNumberGame(self, minNum : int, maxNum : int, chance : int):
  17.         print(self.textart.renderText("Number Guessing Game..."))
  18.         randnumber = randint(minNum, maxNum)
  19.         while chance > 0:
  20.             print("Current Chance Live : {}".format(chance))
  21.             try:
  22.                 n = int(input(f"You Number From {minNum} To {maxNum} : "))
  23.                 if n == randnumber:
  24.                     print("Correct! The Number Was {}".format(n))
  25.                     break
  26.                 else:
  27.                     print("Incorrect Try Again", end="\r")
  28.                     chance -= 1
  29.                 time.sleep(1)
  30.                 os.system("cls" if os.name == "nt" else "clear")
  31.                 if chance == 0:
  32.                     print("Game Over Try Again Later You Ran Out of Chance")
  33.             except ValueError as ex:
  34.                 raise ValueError("Invaild Value : ", ex)
  35.     def GuessWordGame(self, listofword : list[str], chance : int):
  36.         print(self.textart.renderText("Word Guessing Game..."))
  37.         correctword = choice(listofword).lower()
  38.         guesses = ""
  39.         lenword = 0
  40.         while chance > 0:
  41.             if guesses == correctword and lenword == len(correctword):
  42.                 print("You Won You Word is {}".format(correctword.lower()))
  43.                 break
  44.             print("Current Word : ", end="")
  45.             displayword = ''.join([char if char in guesses else "_" for char in correctword])
  46.             print(displayword)
  47.             try:
  48.                 print(" You Have {} Chance of Guessing".format(chance))
  49.                 n = input("Guess the Character of The Word : ").lower()
  50.                 if len(n) != 1 or not n.isalpha():
  51.                     print("invaild Character")
  52.                     continue
  53.                 if n == correctword[lenword]:
  54.                     guesses += n
  55.                     lenword += 1
  56.                     print("Correct!")
  57.                 else:
  58.                     print("Wrong TryAgain")
  59.                     chance -= 1
  60.                 time.sleep(1)
  61.                 os.system("cls" if os.name == "nt" else "clear")
  62.                 if chance == 0:
  63.                     print("Game Over Try Again Later")
  64.             except ValueError as ex:
  65.                 raise ValueError("Invaild Value : ", ex)
  66.     def CalcautorConsoleApp(self):
  67.         print(self.textart.renderText("ConsoleApp Calacutor 101..."))
  68.         expr = ""
  69.         resshow = False
  70.         BoarderLim = 14
  71.         while True:
  72.             print('-'*BoarderLim)
  73.             print(f"|{expr}|" if resshow == False else f"|={expr}|")
  74.             print("| 1   2   3  |\n| 4   5   6  |\n| 7   8   9  |\n| +   -   *  |\n| /   C   =  |")
  75.             n = input('input Here : ')
  76.             vaildopreator = ['-', '+', "/", "*"]
  77.             vaildnum = [str(i) for i in range(10)]
  78.             print('-'*BoarderLim)
  79.             if n.isdigit() and n in vaildnum:
  80.                 if resshow:
  81.                     expr = ''
  82.                     resshow = False
  83.                 expr += n
  84.             elif n in vaildopreator:
  85.                 if resshow:
  86.                     resshow = False
  87.                     expr = ''
  88.                 if expr and expr[-1] not in vaildopreator:
  89.                     expr += n
  90.                 else:
  91.                     print('invaild Input')
  92.             elif n == "=":
  93.                 resshow = True
  94.                 try:
  95.                     expr = str(eval(expr))
  96.                 except Exception as ex:
  97.                     print("invaild Experisson While Resulting... error : ", ex)
  98.                     expr = ''
  99.             elif n == "OFF":
  100.                 print("Calacutor Shutting Down...")
  101.                 break
  102.             else:
  103.                 print("invaild input")
  104.     def SimBankGame(self):
  105.         print(self.textart.renderText("Sim Bank Game..."))
  106.         currentmoney = int(input("input You Current Money : "))
  107.         currentstored = int(input("input You Stored Money : "))
  108.         vaildin = ['e', 'w', 'd']
  109.         print(self.textart.renderText("Starting..Sim Bank Game"))
  110.         while True:
  111.             os.system("cls" if os.name == "nt" else "clear")
  112.             print("Current Money in Bank : {}\nCurrent Money : {}".format(currentstored, currentmoney))
  113.             print('What You Wish For :\nw: WithDraw\nd: Despoit\ne: Exit')
  114.             n = input("input Here : ")
  115.             match n:
  116.                 case 'w':
  117.                     while True:
  118.                         try:
  119.                             j = int(input("How Much Do you Wish To WithDraw : "))
  120.                             if j <= currentstored:
  121.                                 currentmoney += j
  122.                                 currentstored -= j
  123.                             else:
  124.                                 print("Cannot WithDraw Too Many")
  125.                                 continue
  126.                         except ValueError as ex:
  127.                             print("invaild input Did you Input a Actual Number?\n... error : ", ex)
  128.                         break
  129.                 case "d":
  130.                     while True:
  131.                         try:
  132.                             j = int(input("How Much Do you Wish To Despoit : "))
  133.                             if j <= currentmoney:
  134.                                 currentstored += j
  135.                                 currentmoney -= j
  136.                             else:
  137.                                 print("Cannot Despoit Too Many")
  138.                                 continue
  139.                         except ValueError as ex:
  140.                             print("invaild input Did you Input a Actual Number?\n.. error : ", ex)
  141.                         break
  142.                 case 'e':
  143.                     print("Exiting..Sim Bank Game")
  144.                     break
  145.                 case _:
  146.                     print("invaild input")
  147.             time.sleep(1)
  148.             os.system("cls" if os.name == "nt" else "clear")
  149. # Vaildator (in Progress)
  150. class VaildatorRegex:
  151.     def IsVaildPassword(self, password : str) -> bool:
  152.         return True if re.fullmatch(r'^(?=.*[a-z])(?=.*\d)[a-zA-Z0-9._@#$%^&*()<>+\-!]+$', password) and len(password) >= 8 else False
  153.     def IsVaildEmail(self, email : str):
  154.         return True if re.search('[a-zA-Z0-9._]+@+[a-zA-Z]{3,}', email) else False
  155.     def FormatPhoneNumber(self, dig : str) -> bool:
  156.         patterned = re.findall(r'(\d{3})(\d{3})(\d{4})', dig)
  157.         return f'({patterned[0][0]})-{patterned[0][1]}-{patterned[0][2]}' if patterned else 'invaild Phone number'
  158. #Test Result For gProject
  159. if __name__ == "__main__":
  160.     pass
  161.     #gProject = GeekForGeekProject()
  162.     #gProject.GuessNumberGame(0, 10, 11)
  163.     #gProject.GuessWordGame(["Mawin", "John"], 100)
  164.     #gProject.CalcautorConsoleApp()
  165.     #gProject.SimBankGame()
  166.     #Test Result For VaildatorRegex Project
  167.     #vd = VaildatorRegex()
  168.     #print(vd.FormatPhoneNumber('12345678910'))
  169.     #print(vd.IsVaildEmail("[email protected]"))
  170.     #print(vd.IsVaildPassword("sigmaSIGMA!@"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement