Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .breakpoints
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"files": {
"main.py": [
{
"id": "036f67b4-9935-4ce6-b23b-3aa0f4a770f2",
"line": 1,
"version": 1,
"index": 0
}
]
}
}
14 changes: 14 additions & 0 deletions .replit
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
entrypoint = "main.py"
modules = ["python-3.10:v18-20230807-322e88b"]

hidden = [".pythonlibs"]

[nix]
channel = "stable-23_05"

[unitTest]
language = "python3"

[deployment]
run = ["python3", "main.py"]
deploymentTarget = "cloudrun"
168 changes: 168 additions & 0 deletions level_0/E1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Create an online banking system with the following features:

# Users must be able to log in with a username and password.
# If the user enters the wrong credentials three times, the system must lock them out.
# The initial balance in the bank account is $2000.
# The system must allow users to deposit, withdraw, view, and transfer money.
# The system must display a menu for users to perform transactions.

from replit import db
import json
import os


class User:

def __init__(self,
username="",
password="",
status=True,
balance=2000,
_count=0):
self.username = username
self.password = password
self.status = status
self.balance = balance
self._count = 0

def view(self, debug=True):
if debug:
print(
f'Username: {self.username}\tPassword: {self.password}\tStatus: {self.status}\t Balance: ${self.balance}'
)
else:
print(f'Username: {self.username}\tBalance: ${self.balance}')
return self.toJson()

def toJson(self):
return json.dumps(self,
default=lambda o: o.__dict__,
sort_keys=True,
indent=1)

def deposit(self, amount):
self.balance += amount
self.save()
return

def checkFounds(self, amount):
return self.balance >= amount

def withdraw(self, amount):
if self.checkFounds(amount):
self.balance -= amount
self.save()
else:
print("Insufficient funds")
return

def transfer(self, there, amount):
if self.checkFounds(amount):
self.withdraw(amount)
there.deposit(amount)
self.save()
else:
print("Insufficient funds")
return

def checkPassword(self, password):
if self.password == password:
return True
else:
self._count += 1
print(f'Wrong password. Attempts: {self._count} of 3')
if self._count == 3:
self.lockUser()
return False

def lockUser(self):
self.status = False
self.save()
return

def save(self):
db[self.username] = self.toJson()
return

def drawMenu(user,clear = True):
if clear:
os.system('clear')

print(" Please Select an option ".center(50, "="))
print(" 1) - Check balance")
print(" 2) - Deposit")
print(" 3) - Witdraw")
print(" 4) - Transfer")
print(" 5) - Exit \n", end="")
option = int(input())
if option == 1:
user.view(False)
drawMenu(user, False)
elif option == 2:
amount = int(input("Enter amount to deposit: "))
user.deposit(amount)
drawMenu(user)
elif option == 3:
amount = int(input("Enter amount to withdraw: "))
user.withdraw(amount)
drawMenu(user)
elif option == 4:
username = input("Enter username to transfer to: ")
userList = db.get(username)
if (userList != None):
j = json.loads(userList)
u = User(**j)
amount = int(input("Enter amount to transfer: "))
user.transfer(u, amount)
else:
print("User not found")
drawMenu(user, False)
elif option == 5:
drawLogIn()
else:
print(f'{option} is an Invalid option {option == 1}')

#drawMenu(user)
return


def drawLogIn():
os.system('clear')
print(" Please Enter Credentials ".center(50, "="))
print(" Username: ", end="")
username = input()
userList = db.get(username)
if (userList != None):
j = json.loads(userList)
u = User(**j)
u.view()
if (u.status):
logedIn = False
while (u.status and not logedIn):
print(" Password: ", end="")
password = input()
logedIn = u.checkPassword(password)
if (not u.status):
print(f'{username} is locked out')
else:
drawMenu(u)
print("loggedIn")
else:
print(f'{username} is locked out')
else:
print("user dont exist, do you want to create an account? (y/n)",
end="")
create = input()
if (create == "y" or create == "Y"):
print(f'Set a Password for Username {username}: ', end="")
password = input()
user = User(username, password)
db[username] = user.view()
drawMenu(user)

print(" Thank You ".center(50, "="))
return

def main():
print(db.keys())
drawLogIn()
Empty file added level_0/__init__.py
Empty file.
Binary file added level_0/__pycache__/E1.cpython-310.pyc
Binary file not shown.
Binary file added level_0/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
4 changes: 4 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from level_0 import E1

if __name__ == '__main__':
E1.main()
Loading