Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ljonkergouw committed Nov 24, 2022
2 parents af4b50f + 90cd19c commit ace459e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 44 deletions.
76 changes: 35 additions & 41 deletions PythonTrainingGroupB/Portfolio.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,35 @@
class Portfolio:

def __init__(self, user_id):
self.user_id = user_id
self.balance = 0
self.portfolio = {}
self.portfolio_count = len(self.portfolio)

def display_portfolio(self):
print(f"Portfolio displayed for user {self.user_id}:")
print(f'Your Portfolio contains {self.portfolio_count} stocks and your balance is €{self.balance}!')

def add_money(self, amount):
if type(amount) == float or type(amount) == int and amount > 0:
self.balance += amount
print(f'Your balance is now {self.balance}')
else:
print("The amount given is not a positive number!")

def withdraw_money(self, amount):
if amount > self.balance:
print("You are trying to withdraw more money than is currently in your balance!")
print("Please provide an amount which is less or equal to your balance")

elif type(amount) == float or type(amount) == int and amount > 0:
print(f"{amount} is deducted from your balance which is {self.balance}")
self.balance -= amount
print(f'Your balance is now {self.balance}')
else:
print("The amount given is not a positive number!")


if __name__ == '__main__':
Port1 = Portfolio('Louk123')
Port1.display_portfolio()
Port1.add_money(-150)
Port1.add_money(10000)
Port1.add_money(15000)

Port1.withdraw_money(24499)
Port1.withdraw_money(600)
import json

with open('Portfolios.json', 'r') as j:
portfolios = json.loads(j.read())

def get_portfolio(user_name):
if user_name in [portfolio['username'] for portfolio in portfolios]:
print([portfolio for portfolio in portfolios if portfolio['username'] == user_name][0]['portfolio'])
else:
print('Portfolio does not exist')

get_portfolio('luuk')

def display_portfolio(self):
print(f"Portfolio displayed for user {self.user_id}:")
print(f'Your Portfolio contains {self.portfolio_count} stocks and your balance is €{self.balance}!')

def add_money(self, amount):
if type(amount) == float or type(amount) == int and amount > 0:
self.balance += amount
print(f'Your balance is now {self.balance}')
else:
print("The amount given is not a positive number!")

def withdraw_money(self, amount):
if amount > self.balance:
print("You are trying to withdraw more money than is currently in your balance!")
print("Please provide an amount which is less or equal to your balance")

elif type(amount) == float or type(amount) == int and amount > 0:
print(f"{amount} is deducted from your balance which is {self.balance}")
self.balance -= amount
print(f'Your balance is now {self.balance}')
else:
print("The amount given is not a positive number!")
2 changes: 2 additions & 0 deletions PythonTrainingGroupB/Portfolios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[{"username": "louk123", "portfolio":{"balance": 500, "portfolio": {"AAPL": 5, "IBM": 1}}},
{"username": "luuk", "portfolio":{"balance": 1500, "portfolio": {"AAPL": 1, "IBM": 2}}}]
7 changes: 4 additions & 3 deletions PythonTrainingGroupB/User.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class UserName:
from Portfolio import portfolio_information
class user_name:

def __init__(self, user_id, password):
self.user_id = user_id
Expand All @@ -8,8 +9,8 @@ def welcome_message(self):
print(f"Welcome {self.user_id}!\n\nThe user information of user_id {self.user_id}: No additional information")

def create_portfolio(self):
pass
portfolio = portfolio_information(self.user_id)

if __name__ == '__main__':
User1 = UserName('louk123', 'ABC123', 'Louk')
User1 = user_name('louk123', 'ABC123')
User1.welcome_message()

0 comments on commit ace459e

Please sign in to comment.