Skip to content

Instantly share code, notes, and snippets.

@Spyder-0
Created October 23, 2022 09:23
Show Gist options
  • Save Spyder-0/a7ed20e790f1b29b971ccd32cffac821 to your computer and use it in GitHub Desktop.
Save Spyder-0/a7ed20e790f1b29b971ccd32cffac821 to your computer and use it in GitHub Desktop.
OOB Command-Input-Style Python Code in Python
# Bank Simulator
# A Flexible Command Input OOP
# Use this as an Example to make Your Command-Input-Style Code
import time
import sys
Money = 0
# List of Functions to Execute
class BankCommands():
# Display how Much Money is in Your Account.
def Balance():
global Money
global User
print("\n[SYS] Your Current Balance | {} | {}.\n".format(User, Money))
# Take Money Out of Your Account.
def Deposit():
global Money
print("\n[SYS] How much do you want to deposit?")
# Give an Error when you don't Type and Integer.
try:
DepositAmount = float(input("[INPUT] Amount: "))
Money = Money + DepositAmount
print("[SYS] {} was put into your account.\n".format(DepositAmount))
except:
print("[ERROR] Invalid Input.\n")
# Take Money Out of Your Account.
def Withdraw():
global Money
print("\n[SYS] How much money would you like to withdraw?")
# Give an Error when you don't Type and Integer.
try:
WithdrawAmount = float(input("[INPUT] Amount: "))
while Money - WithdrawAmount < 0:
print("[ERROR] Maximum withdrawal amount is: {}.".format(Money))
WithdrawAmount = float(input("[INPUT] Amount: "))
print("[SYS] {} was withdrawed from your account.\n".format(WithdrawAmount))
Money = Money - WithdrawAmount
except:
print("[ERROR] Invalid Input.\n")
# Exit the Program.
def Exit():
print("\n[SYS] Thank you for using the Bank Simulator, {}.".format(User))
time.sleep(1)
print("[SYS] See you later!")
time.sleep(3)
sys.exit()
# Display the Help Command.
def Help():
print("\n[SYS] List of Commands:-")
time.sleep(0.1)
print("| Balance or Bal: Shows how much money is in your account.")
time.sleep(0.1)
print("| Deposit or Dep: Put money into your account.")
time.sleep(0.1)
print("| Withdraw or Wit: Take out money from your account.")
time.sleep(0.1)
print("| Exit: Exit the Program.")
time.sleep(0.1)
print("| Help: Shows this.\n")
class MainProgram():
# What Function to Execute Based on Command Input.
def Start():
if command == "balance" or command == "bal":
time.sleep(0.2)
BankCommands.Balance()
elif command == "deposit" or command == "dep":
time.sleep(0.2)
BankCommands.Deposit()
elif command == "withdraw" or command == "wit":
time.sleep(0.2)
BankCommands.Withdraw()
elif command == "exit":
time.sleep(0.2)
BankCommands.Exit()
elif command == "help":
time.sleep(0.2)
BankCommands.Help()
else:
print("[ERROR] Command not found, try 'Help'.")
# Intro
print("[SYS] Welcome to the Bank Simulator, enter a command below! Type 'Help' for more details.")
time.sleep(0.1)
print("[SYS] To get started, enter your Username.")
User = input("[INPUT] Username: ")
time.sleep(0.1)
print("[SYS] Welcome to the bank, {}.\n".format(User))
time.sleep(0.2)
# Command Input
while True:
time.sleep(0.1)
command = input("[Command]$ ").lower()
MainProgram.Start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment